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

            Bug ID: 128323
           Summary: Accepts-invalid in-class initializer accepted for a
                    static const volatile integral data member
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: 652023330028 at smail dot nju.edu.cn
  Target Milestone: ---

GCC accepts the following ill-formed program without any diagnostics:

https://godbolt.org/z/bjYsezsM8
  struct X { static const volatile int m = 1; };
  enum E { e };
  struct Y { static const volatile E n = e; };


 $ g++ -std=c++17 -pedantic-errors -c t.cpp
 $ echo $?
 0

Expected: an error.

[class.static.data]/4 allows an in-class initializer only for a non-volatile
non-inline const static data member of integral or enumeration type. GCC
already enforces the integral/enumeration part (e.g. 'static const double d =
1.0;' is rejected), but not the non-volatile part.


Clang trunk rejects it:

 $ clang++ -std=c++17 -pedantic-errors -c t.cpp
 t.cpp:1:38: error: static const volatile data member must be initialized out
of line

Reply via email to