Feature #686

LLVM clang: error: default initialization of an object of const type 'class Exiv2::IptcData const' requires a user-provided default constructor

Added by Nikolai Saoukh over 7 years ago. Updated over 7 years ago.

Status:ClosedStart date:04 Mar 2010
Priority:LowDue date:
Assignee:-% Done:

100%

Category:miscellaneous
Target version:0.20

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.

const-init.txt Magnifier (1.28 KB) Nikolai Saoukh, 04 Mar 2010 07:46

Associated revisions

Revision 2047
Added by Andreas Huggel over 7 years ago

#686: Removed const-qualifier to make things comply with the C++ standard.

History

#1 Updated by Andreas Huggel over 7 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;
}

#2 Updated by Nikolai Saoukh over 7 years ago

Yes, the same error message for 'const B b;'.

#3 Updated by Andreas Huggel over 7 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.

#4 Updated by Andreas Huggel over 7 years ago

"Fixing" the Exiv2 code should be simple: just remove the 'const'-qualifier in the lines that cause the error.

#5 Updated by Nikolai Saoukh over 7 years ago

I will file bug report for clang (still moving target). There are some clang crashes with your code too.

Stay tuned ;-)

#6 Updated by Andreas Huggel over 7 years ago

Did you get any feedback from the clang developers?

#7 Updated by Nikolai Saoukh over 7 years ago

LLVM developer Chandler Carruth <> 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.

#8 Updated by Andreas Huggel over 7 years ago

Thanks for the update. Now I also found the clang bugreport: http://llvm.org/bugs/show_bug.cgi?id=6772

#9 Updated by Andreas Huggel over 7 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.

#10 Updated by Andreas Huggel over 7 years ago

  • Status changed from Resolved to Closed

Also available in: Atom PDF

Redmine Appliance - Powered by TurnKey Linux