public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/97566] New: [[no_unique_address]] causes miscompiles when mixed with EBO in constexpr context
@ 2020-10-25  3:37 natattak at gmail dot com
  2020-10-29 16:34 ` [Bug c++/97566] " redi at gcc dot gnu.org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: natattak at gmail dot com @ 2020-10-25  3:37 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 97566
           Summary: [[no_unique_address]] causes miscompiles when mixed
                    with EBO in constexpr context
           Product: gcc
           Version: 10.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: natattak at gmail dot com
  Target Milestone: ---

Example: (https://godbolt.org/z/Y5q5br)

  #include <memory>
  #include <cassert>

  // error disappears if E doesn't inherit from B
  struct B {};
  struct E : B {};

  struct counter {
    constexpr counter() = default;
    constexpr void inc() {
      size++;
    }

    // error disappears if you remove or reorder this value
    int unused = 0;
    int size = 0;
    [[no_unique_address]] E empty = {};
  };

  constexpr int test() {
    counter x;
    x.inc();
    return x.size;
  }

  int main() {
    assert(test() == 1);        // works, unless optimisations enabled
    static_assert(test() == 1); // fails, always
  }

In particular, the runtime assertion only passes on -O0; any higher
optimisation e.g. -O1 causes it to fail.

Compiled as `g++ -std=c++20`.

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

end of thread, other threads:[~2021-08-20 14:48 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-25  3:37 [Bug c++/97566] New: [[no_unique_address]] causes miscompiles when mixed with EBO in constexpr context natattak at gmail dot com
2020-10-29 16:34 ` [Bug c++/97566] " redi at gcc dot gnu.org
2021-01-26  1:14 ` jason at gcc dot gnu.org
2021-01-26 20:01 ` cvs-commit at gcc dot gnu.org
2021-01-26 20:11 ` jason at gcc dot gnu.org
2021-02-09  1:52 ` cvs-commit at gcc dot gnu.org
2021-06-26  4:13 ` cvs-commit at gcc dot gnu.org
2021-07-07 21:36 ` cvs-commit at gcc dot gnu.org
2021-08-20 14:48 ` soap at gentoo dot 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).