public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/110828] New: union constexpr dtor not constexpr when used in member array
@ 2023-07-27 10:06 gccbugbjorn at fahller dot se
  2023-07-27 14:22 ` [Bug c++/110828] " ppalka at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: gccbugbjorn at fahller dot se @ 2023-07-27 10:06 UTC (permalink / raw)
  To: gcc-bugs

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-07-27 17:54 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-27 10:06 [Bug c++/110828] New: union constexpr dtor not constexpr when used in member array gccbugbjorn at fahller dot se
2023-07-27 14:22 ` [Bug c++/110828] " ppalka at gcc dot gnu.org
2023-07-27 16:25 ` gccbugbjorn at fahller dot se
2023-07-27 17:54 ` pinskia at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).