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

            Bug ID: 89781
           Summary: Misleading error messages when initializing a static
                    data member in-class
           Product: gcc
           Version: 9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: redbeard0531 at gmail dot com
  Target Milestone: ---

The error messages make sense in a pre-c++17 world before inline variables
existed. Now they are lies!

struct X{};
struct Y { static X x = {}; };

<source>:2:21: error: 'constexpr' needed for in-class initialization of static
data member 'X Y::x' of non-integral type [-fpermissive]
 struct Y { static X x = {}; };
                     ^

The error is even worse when X can't be a constexpr variable:


struct X{ X(); };
struct Y { static X x = {}; };

<source>:2:21: error: in-class initialization of static data member 'X Y::x' of
non-literal type
 struct Y { static X x = {}; };
                     ^
<source>:2:26: error: temporary of non-literal type 'X' in a constant
expression
 struct Y { static X x = {}; };
                          ^
<source>:1:8: note: 'X' is not literal because:
 struct X{ X(); };
        ^
<source>:1:8: note:   'X' is not an aggregate, does not have a trivial default
constructor, and has no 'constexpr' constructor that is not a copy or move
constructor



This compiles just fine:

struct X{ X(); };
struct Y { static inline X x = {}; };

All examples were passing -std=c++17.

Reply via email to