[Bug c++/90951] [8/9/10 Regression] error initializing a constexpr array of a struct with const member

msebor at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Thu Jun 20 20:46:00 GMT 2019


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

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to work|                            |4.8.5
            Summary|[9/10 Regression] error     |[8/9/10 Regression] error
                   |initializing a constexpr    |initializing a constexpr
                   |array of a struct with      |array of a struct with
                   |const member                |const member
      Known to fail|                            |10.0, 4.9.1, 5.5.0, 6.4.0,
                   |                            |7.4.0, 8.3.0, 9.1.0

--- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> ---
Actually, I don't think this is related to r270155.  When the test case is
modified as shown below it fails to compile even prior to the change and all
the way to GCC 4.9.  It is accepted by GCC 4.8.  It needs -std=c++11:


#define assert(expr) static_assert (expr, #expr)

struct S { const char a[2]; };

constexpr struct S a[1][1][1] = { };

assert ('\0' == *a[0][0][0].a);

t.C:7:29: error: use of deleted function ‘S::S()’
    7 | assert ('\0' == *a[0][0][0].a);
      |                             ^
t.C:1:37: note: in definition of macro ‘assert’
    1 | #define assert(expr) static_assert (expr, #expr)
      |                                     ^~~~
t.C:3:10: note: ‘S::S()’ is implicitly deleted because the default definition
would be ill-formed:
    3 |   struct S { const char a[2]; };
      |          ^
t.C:3:10: error: uninitialized const member in ‘struct S’
t.C:3:25: note: ‘const char S::a [2]’ should be initialized
    3 |   struct S { const char a[2]; };
      |                         ^
t.C:7:31: error: use of deleted function ‘S::S()’
    7 | assert ('\0' == *a[0][0][0].a);
      |                               ^
t.C:7:14: error: non-constant condition for static assertion
    7 | assert ('\0' == *a[0][0][0].a);
      |         ~~~~~^~~~~~~~~~~~~~~~
t.C:1:37: note: in definition of macro ‘assert’
    1 | #define assert(expr) static_assert (expr, #expr)
      |                                     ^~~~
t.C:7:14: error: use of deleted function ‘S::S()’
    7 | assert ('\0' == *a[0][0][0].a);
      |         ~~~~~^~~~~~~~~~~~~~~~
t.C:1:37: note: in definition of macro ‘assert’
    1 | #define assert(expr) static_assert (expr, #expr)
      |                                     ^~~~


More information about the Gcc-bugs mailing list