The Clang documentation clearly explains that
If a class or structure does not have a custom default constructor, C ++ does not allow you to build a const instance like this ([dcl.init], p9)
The rationale is that if the const object is not properly initialized, it cannot be changed later. The following code has only the default constructor declared for Test , but all its members have initializers in the class,
therefore, the rationale for user- providing the default constructor seems superfluous to me. Indeed, g ++ 4.8.1 will compile it without problems ( Online Example ), although Clang <= 3.2 does not.
Questions : why the combination of full inital initializers + the default constructor declared by the user is not enough to build a const object by default? Is there a fix for C ++ 14 Standard?
UPDATE : can anyone try Clang 3.3 / 3.4 to see if this is fixed compared to Clang 3.2?
c ++ c ++ 11 c ++ 14 default-constructor
TemplateRex Jul 05 '13 at 22:20 2013-07-05 22:20
source share