https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118722

            Bug ID: 118722
           Summary: accepted undefined static integral data member
           Product: gcc
           Version: 14.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ing.russomauro at gmail dot com
  Target Milestone: ---

hello,

I wonder the following code (https://godbolt.org/z/fj7Mo8Ynx) is accepted by
gcc 14.2 (and also Clang 19.0 and MVSC v19);



#include <iostream>

struct T{
    static const int x = 1;
};

//const int T::x;

int main (){ 
   std::cout << T::x << std::endl;
}


>From C++20 standard I still read in [class.static.data]:

p3: The declaration of a non-inline static data member in its class definition
is not a definition and may be of an incomplete type other than cv void. The
definition for a static data member that is not defined inline in the class
definition shall appear in a namespace scope enclosing the member’s class
definition. ...

P4: If a non-volatile non-inline const static data member is of integral or
enumeration 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. The member shall still be
defined in a namespace scope if it is odr-used in the program and the namespace
scope definition shall not contain an initializer . ...


I also noticed in the past there were bugs correctly rejected where sample code
missed the definition out of the class, while users wondered about linking
error, e.g. PR 25220, PR 43720, etc.

Am I missing some detail ?

Reply via email to