小编dec*_*uto的帖子

clang ++失败但g ++成功地在赋值中使用强制转换为const-unrelated-type运算符

这是一个简短的例子,用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)编译它

如果 …

g++ conversion-operator language-lawyer c++11 clang++

9
推荐指数
1
解决办法
296
查看次数

没有删除任何功能时,Clang会抱怨"无法覆盖已删除的功能"

在下面的简单代码片段中:

#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都没有在此代码中报告错误.这是一个铿锵的缺陷还是什么?

overriding language-lawyer virtual-destructor c++11 clang++

6
推荐指数
1
解决办法
1857
查看次数