Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where in the C++ Standard does it say that the definition of a const built-in type variable must be initialized?

I have been looking for this in N4713 for more than two hours to no avail.

like image 240
WaldB Avatar asked Dec 11 '22 07:12

WaldB


1 Answers

I have a C++14 draft which says, at 7.1.6.1 [dcl.type.cv]:

As described in 8.5, the definition of an object or subobject of const-qualified type must specify an initializer or be subject to default-initialization

8.5 [dcl.init] says (clause 7):

To default-initialize an object of type T means:

[for a non class, non array type]:

... no initialization is performed

And immediately follows with:

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.

Therefore a const built-in must have an initializer, since otherwise it would be default-initialized and that is not allowed.

like image 172
davmac Avatar answered Dec 12 '22 19:12

davmac