Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++11 constexpr bug,std::与多重继承相同吗_C++11_Constexpr_Typetraits - Fatal编程技术网

C++11 constexpr bug,std::与多重继承相同吗

C++11 constexpr bug,std::与多重继承相同吗,c++11,constexpr,typetraits,C++11,Constexpr,Typetraits,使用VS2015编译: template <typename Owner, typename C, typename R, typename... Args> constexpr bool FunctionBelongsTo(R(C::*)(Args...) const) { return std::is_same<C, Owner>::value; } class C { public: int x; }; class D { public: int y;

使用VS2015编译:

template <typename Owner, typename C, typename R, typename... Args>
constexpr bool FunctionBelongsTo(R(C::*)(Args...) const)
{
  return std::is_same<C, Owner>::value;
}

class C
{
public:
  int x;
};
class D
{
public:
  int y;
};
class M : public C, public D
{
public:
  void f() const {}
};

static_assert(FunctionBelongsTo<M>(&M::f) != true, "TRUE");
这个
std::is__same
表达式肯定是常量

奇怪的是,这个错误似乎是在这个非常特殊的情况下调用的,
M
是多重继承的。从
M
中删除任何一个基类,它编译得很好(即,它会像预期的那样发出
static\u assert
),但是当
M
像这样被多次继承时,它会决定表达式不是常量


。。。有什么好处?新手错误?

VS2015 Udpate 2 RC(CL版本19.00.23824.1)似乎解决了这个问题。您还可以在上使用稍旧的版本进行验证,因此我希望在RTM更新时它保持不变。

您的代码是合法的,这是visual studio造成的,因为到目前为止,许多类型特征工作人员只得到了部分支持。gcc和clang都编译了代码。我认为最麻烦的是方法指针。它不会将其作为编译时常量进行计算。@bolov很明显,但正如我所说,如果您从乘法继承类中删除一个基类,它会进行计算。最新的更新3仍然没有解决这个问题。@sniel我目前没有安装更新3,但在VS“15”预览4中,我得到了预期的
main.cpp(25):错误C2338:TRUE
,网络编译器上的错误相同。
error C2131: expression did not evaluate to a constant
note: a non-constant (sub-)expression was encountered