Re: static-const-integral in-class-init without explicit definition

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 21 September 2014 15:08, Raja Gopal Muralidharan wrote:
>>I think GCC has always supported it, because it's >valid C++. Do you
>>have reason to believe otherwise?
>
> C++ standard, ISO/IEC 14882: 2003 states,
> " If a static data member is of const integral or const enumeration type,
> its declaration in the class definition can specify a constant-initializer
> which shall be an integral constant expression (5.19). In that case, the
> member can appear in integral constant expressions. The member shall still
> be defined in a namespace scope if it is used in the program and the
> namespace scope definition shall not contain an initializer."
>
> So, though it is a static const integral, if used in the program, it shall
> be defined is what the C++ standard says.

The 2003 standard didn't clearly define what was meant by "used in the program".

> But, there is also a defect raised regd. this,
> http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#454.

That is the case that applies to your program, because an
lvalue-to-rvalue conversion in applied immediately, so the variable
doesn't need to be defined. As stated in the DR, that relaxation of
the rule corresponds to "what users expect and all compilers that I
know of already do."

> But, C++11 states,
> $9.4.2
> "3. If a non-volatile const static data member is of integral or enumeration
> type,it's declaration in the class definition can specify a
> brace-or-equal-initialized in which every initializer-clause that is an
> assignment expression is a constant expression(5.19).A static data member of
> literal type can be declared in the class definition with the
> constexprspecifier;if so,it's 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 expression.—endnote] The member
> shall still be defined in a namespace scope if it is odr-used(3.2)in the
> program and the name space scope definition shall not contain an
> initializer."
>
> My thoughts were, either wording is corrected in C++11 or C++11 started
> supporting it.

C++11 introduced the term odr-used to formally define what was poorly
specified in the previous standard. DR 454 and the specification of
udr-use are intended to match what was already existing practice for
compilers.

> So, I thought of understanding , since when GCC started to supporting it to
> get an idea.

GCC has supported it long before the standard was clarified to match
what compilers already did in practice.

I checked back to GCC 4.1.0 and your program works with that version.
I expect it will work with all versions.





[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux