Feature #686
LLVM clang: error: default initialization of an object of const type 'class Exiv2::IptcData const' requires a user-provided default constructor
100%
Description
Recent clang issues the error message from subject. All the same messages are in the attachment. I am not sure it is an error.
Files
Associated revisions
History
Updated by Andreas Huggel over 11 years ago
Does the following code cause the same error (it works fine with g++)?
struct A { A() {} }; class B { A a_; }; int main() { const B b; }
Updated by Andreas Huggel over 11 years ago
I don't see anything wrong with that code, but I'm admittedly not particularly fluent with the standard. It would be interesting to hear what the people at LLVM/clang have to say about this one. Pls share a pointer here if you ask them.
Updated by Andreas Huggel over 11 years ago
"Fixing" the Exiv2 code should be simple: just remove the 'const'-qualifier in the lines that cause the error.
Updated by Nikolai Saoukh over 11 years ago
I will file bug report for clang (still moving target). There are some clang crashes with your code too.
Stay tuned ;-)
Updated by Nikolai Saoukh over 11 years ago
LLVM developer Chandler Carruth <chandlerc@gmail.com> replied:
ccd.cpp:12:10: error: default initialization of an object of const type 'B
const' requires a user-provided default constructor
Clang is correct: C++'03 [dcl.init] p9: If no initializer is specified for an
object, and the object is of (possibly cv-qualified) non-POD class type (or
array thereof), the object shall be default-initialized; if the object is of
const-qualified type, the underlying class type shall have a user-declared
default constructor.
The user declared default constructor for A makes A non-POD. The A member in B
makes B non-POD, and thus this rule kicks in, and the code provided is invalid.
You could re-open as a request for a GCC-compatibility setting to allow such
code, but I don't personally see a lot of value in it. Perhaps others do, so
feel free to re-open if you want to pursue that path.
Updated by Andreas Huggel over 11 years ago
Thanks for the update. Now I also found the clang bugreport: http://llvm.org/bugs/show_bug.cgi?id=6772
Updated by Andreas Huggel over 11 years ago
- Category set to miscellaneous
- Status changed from New to Resolved
- Target version set to 0.20
- % Done changed from 0 to 100
Removed const-qualifier.
#686: Removed const-qualifier to make things comply with the C++ standard.