public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/111226] New: constexpr doesn't detect change of union to empty member
@ 2023-08-29 13:21 nathanieloshead at gmail dot com
  2023-09-07 19:01 ` [Bug c++/111226] " ppalka at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: nathanieloshead at gmail dot com @ 2023-08-29 13:21 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 111226
           Summary: constexpr doesn't detect change of union to empty
                    member
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: nathanieloshead at gmail dot com
  Target Milestone: ---

While working on a patch for PR101631, I found that the following code is
currently incorrectly handled by GCC: (https://godbolt.org/z/1YevacMK3)


struct Empty {};

union U {
  int x;
  Empty e;
};

constexpr int foo() {
  U u{ 10 };
  u.e = {};
  return u.x;  // incorrectly accepted, even pre-C++20
}
constexpr auto y = foo();

constexpr Empty bar() {
  U u{ 10 };
  u.e = {};
  return u.e;  // incorrectly errors, thinks active member is still 'x'
}
constexpr auto x = bar();


The cause seems to be that the zero-sized trivial assignment is removed in
call.cc (since PR43075) and after constant folding is no longer in the tree
that the constexpr handling machinery receives.

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

* [Bug c++/111226] constexpr doesn't detect change of union to empty member
  2023-08-29 13:21 [Bug c++/111226] New: constexpr doesn't detect change of union to empty member nathanieloshead at gmail dot com
@ 2023-09-07 19:01 ` ppalka at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: ppalka at gcc dot gnu.org @ 2023-09-07 19:01 UTC (permalink / raw)
  To: gcc-bugs

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

Patrick Palka <ppalka at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |accepts-invalid,
                   |                            |rejects-valid
             Status|UNCONFIRMED                 |NEW
                 CC|                            |ppalka at gcc dot gnu.org
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2023-09-07

--- Comment #1 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Confirmed.

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

end of thread, other threads:[~2023-09-07 19:01 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-29 13:21 [Bug c++/111226] New: constexpr doesn't detect change of union to empty member nathanieloshead at gmail dot com
2023-09-07 19:01 ` [Bug c++/111226] " ppalka 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).