对于此代码:
struct S { S(int m): m(m) {} constexpr int f() const { return m; } int m; }; int main() { S s(1); }
它是由clang 3.6,3.7和3.8编译而没有警告或错误,-std = c 14.但是在5.x中出现以下错误:
main.cpp:4:19: error: enclosing class of constexpr non-static member function 'int S::f() const' is not a literal type constexpr int f() const { return m; } ^ main.cpp:1:8: note: 'S' is not literal because: struct S ^ main.cpp:1:8: note: 'S' is not an aggregate,does not have a trivial default constructor,and has no constexpr constructor that is not a copy or move constructor
哪个编译器是正确的,为什么?
我查看了C 14 [dcl.constexpr] / 3中的要求,其中说constexpr函数“它的每个参数类型都应该是文字类型”,但该部分没有明确提到成员函数,也没有说明是否为本条款的目的,隐含的*作为参数.