constexpr非静态成员函数与非constexpr构造函数(gcc,clang不同)

时间:2016-04-08 00:11:13

标签: c++ gcc clang c++14 constexpr

对于此代码:

-std=c++14

它被编译时没有警告或错误被clang 3.6,3.7和3.8与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 编译。但是在g ++ 5.x中会出现以下错误:

constexpr

哪种编译器正确?为什么?

我查看了C ++ 14 [dcl.constexpr] / 3中的要求,其中说明对于*this函数,“它的每个参数类型都应该是文字类型”,但该部分没有明确说明提及成员函数,并没有说出隐含的CREATE TABLE Table_name ( EmpID INT PRIMARY KEY, MgrID INT REFERENCES Table_name ( EmpID ), Name VARCHAR2(10), Role VARCHAR2(10) ); INSERT INTO table_name SELECT 1, NULL, 'Amy', 'CEO' FROM DUAL UNION ALL SELECT 2, 1, 'Bob', 'Director' FROM DUAL UNION ALL SELECT 3, 1, 'Carol', 'Director' FROM DUAL UNION ALL SELECT 4, 2, 'Deb', 'CIO' FROM DUAL; 是否作为本条款的参数。

1 个答案:

答案 0 :(得分:7)

这是为C ++ 14修复的核心缺陷

http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#1684

Clang被修补了

https://groups.google.com/a/isocpp.org/forum/#!topic/std-discussion/6jM8M8FUs30

这是GCC的跟踪器,但它看起来并不像任何人已经解决过它

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66297