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.
  • [Bug c++/111226] New: conste... nathanieloshead at gmail dot com via Gcc-bugs

Reply via email to