这是一个简短的例子,用clang重现这个"没有可行的转换"柠檬,但对编译器行为的g ++差异有效.
#include <iostream>
struct A {
int i;
};
#ifndef UNSCREW_CLANG
using cast_type = const A;
#else
using cast_type = A;
#endif
struct B {
operator cast_type () const {
return A{i};
}
int i;
};
int main () {
A a{0};
B b{1};
#ifndef CLANG_WORKAROUND
a = b;
#else
a = b.operator cast_type ();
#endif
std::cout << a.i << std::endl;
return EXIT_SUCCESS;
}
Run Code Online (Sandbox Code Playgroud)
住在Godbolt的
g ++(4.9,5.2)默默地编译; 而clang ++(3.5,3.7)编译它
如果 …
在下面的简单代码片段中:
#include <cstddef>
struct B
{
virtual ~B() = default;
static void operator delete(void *, int);
static void * operator new(size_t, int);
};
struct C : B
{
virtual ~C() = default;
};
Run Code Online (Sandbox Code Playgroud)
clang 3.7抱怨"未删除的功能'〜C'无法覆盖已删除的功能":http: //goo.gl/Ax6oth
Visual Studio和GCC都没有在此代码中报告错误.这是一个铿锵的缺陷还是什么?