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

            Bug ID: 110828
           Summary: union constexpr dtor not constexpr when used in member
                    array
           Product: gcc
           Version: 13.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gccbugbjorn at fahller dot se
  Target Milestone: ---

The following code does not compile with g++ 13.1 or g++ trunk
82c2a34b2f2c1a06eff672eba2e447b53f35d7b0

union type {
    constexpr type(){}
    constexpr ~type() {}
    int t;
};

struct S
{
    constexpr S() = default;
    constexpr bool f() const { return true;}
private:
    type v[1];
};


static_assert(S{}.f());

The error message is:
source.cpp:16:20: error: non-constant condition for static assertion
   16 | static_assert(S{}.f());
      |               ~~~~~^~
source.cpp:16:23:   in 'constexpr' expansion of '(&<anonymous>)->S::~S()'
source.cpp:7:8: error: '(((type*)(&<anonymous>.S::v)) != 0)' is not a constant
expression
    7 | struct S
      |        ^

Two simple changes can each make it compile.

1. Comment out the constexpr destructor for 'type'
2. Remove [1] from the declaration of member variable S::v such that it is not
an array.

Link to compiler explorer: https://godbolt.org/z/q3KcKrPh1

Reply via email to