Title
Misleading note regarding initialized static data members
Status
dup
Section
11.4.9.3 [class.static.data]
Submitter
Jason Merrill

Created on 2010-09-30.00:00:00 last changed 147 months ago

Messages

Date: 2010-11-15.00:00:00

Rationale (November, 2010):

This is a duplicate of issue 1101.

Date: 2022-11-20.07:54:16

11.4.9.3 [class.static.data] paragraph 3 says,

If a static data member is of const literal type, its declaration in the class definition can specify a brace-or-equal-initializer in which every initializer-clause that is an assignment-expression is a constant expression. A static data member of literal type can be declared in the class definition with the constexpr specifier; if so, its declaration shall specify a brace-or-equal-initializer in which every initializer-clause that is an assignment-expression is a constant expression. [Note: In both these cases, the member may appear in constant expressions. —end note]

The note is misleading; to be used for its value in a constant expression, the static data member must either be declared constexpr or have integral or enumeration type. Though strictly speaking, the note is true, because any static data member, initialized or not, may appear in an address constant expression if its address is taken.

I think the right fix is to change “const literal” back to “const integral or const enumeration.” It would also be nice to avoid the duplication of text.

History
Date User Action Args
2012-02-27 00:00:00adminsetmessages: + msg3855
2012-02-27 00:00:00adminsetstatus: open -> dup
2010-09-30 00:00:00admincreate