The following code compiles fine with GCC:
constexpr struct {} s;
But Clang rejects it with the following error:
error: default initialization of an object of const type 'const struct (anonymous struct at …)' without a user-provided default constructor
I've tested all versions of GCC and Clang that I was able to find at https://gcc.godbolt.org/. Each version of GCC accepts the code and each version of Clang rejects it.
I wonder which compiler is correct in this case?
What does the standard say about this?
Answer
Clang adheres to the following passage in [dcl.init]/7:
If a program calls for the default initialization of an object of a const-qualified type
T
,T
shall be a class type with a user-provided default constructor.
This wording is defective and hence ignored by GCC (and, as of v3.9, also by Clang).
The above quote differs from core issue 253's due to N2762 moving/adjusting paragraph 9 as cited.
No comments:
Post a Comment