[Bug c++/104142] [9/10/11/12 Regression] Spurios warning unused-variable on const static variable and defaulted constructor

jakub at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Fri Jan 28 11:43:38 GMT 2022


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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |mpolacek at gcc dot gnu.org,
                   |                            |ppalka at gcc dot gnu.org

--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
If we want the same warning, we'd need to probably special case const vars with
defaulted default ctors and empty classes, if it isn't empty class, both of
these are rejected already:
pr104142.C:2:16: error: uninitialized ‘const a’ [-fpermissive]
    2 | static const A a;
      |                ^
pr104142.C:1:8: note: ‘const struct A’ has no user-provided default constructor
    1 | struct A { int a; };
      |        ^
pr104142.C:1:16: note: and the implicitly-defined constructor does not
initialize ‘int A::a’
    1 | struct A { int a; };
      |                ^
pr104142.C:5:16: error: uninitialized ‘const b’ [-fpermissive]
    5 | static const B b;
      |                ^
pr104142.C:4:8: note: ‘const struct B’ has no user-provided default constructor
    4 | struct B { B()=default; int b; };
      |        ^
pr104142.C:4:12: note: constructor is not user-provided because it is
explicitly defaulted in the class body
    4 | struct B { B()=default; int b; };
      |            ^
pr104142.C:4:29: note: and the implicitly-defined constructor does not
initialize ‘int B::b’
    4 | struct B { B()=default; int b; };
      |                             ^


More information about the Gcc-bugs mailing list