[Bug c++/105191] New: '<expression>' "is not a constant expression" regression in GCC 12

strager.nds at gmail dot com gcc-bugzilla@gcc.gnu.org
Thu Apr 7 03:07:24 GMT 2022


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

            Bug ID: 105191
           Summary: '<expression>' "is not a constant expression"
                    regression in GCC 12
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: strager.nds at gmail dot com
  Target Milestone: ---

Created attachment 52763
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=52763&action=edit
C++ source file which demonstrates the issue

Compared to GCC 10 and GCC 11.2, GCC 12 reports an error when compiling my
program. A reduced test case is attached (test.cpp). I think the error is a
false positive; I think my code is valid C++.

g++
(Compiler-Explorer-Build-gcc-d8ac63e4c638a814c2cb7a9f4cebb6606caa4985-binutils-2.36.1)
12.0.1 20220404 (experimental):
g++ (GCC) 12.0.1 20220401 (Red Hat 12.0.1-0):
$ /usr/bin/c++ -std=gnu++11 test.cpp -c
test.cpp:17:5: error: non-constant array initialization
   17 |   D{},
      |     ^
test.cpp:18:1: error: call to non-‘constexpr’ function ‘C::C()’
   18 | };
      | ^
test.cpp:7:8: note: ‘C::C()’ is not usable as a ‘constexpr’ function because:
    7 | struct C {
      |        ^
test.cpp:9:5: note: defaulted default constructor does not initialize ‘B C::b’
    9 |   B b;
      |     ^
$ /usr/bin/c++  -std=gnu++20 test.cpp -c
test.cpp:18:1: error: ‘D [1]{D{C [1]{C{A{((const char*)"")}}}}}’ is not a
constant expression
   18 | };
      | ^

g++-10 (Ubuntu 10.3.0-1ubuntu1~20.04) 10.3.0:
g++ (Compiler-Explorer-Build-gcc--binutils-2.36.1) 11.2.0:
$ g++-10 -std=gnu++11 test.cpp -c
(no error)
$ g++-10 -std=gnu++20 test.cpp -c
(no error)


More information about the Gcc-bugs mailing list