public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/112591] New: variant allows for creating multiple empty objects at same address
@ 2023-11-17 16:02 barry.revzin at gmail dot com
  2023-11-17 16:53 ` [Bug libstdc++/112591] " barry.revzin at gmail dot com
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: barry.revzin at gmail dot com @ 2023-11-17 16:02 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 112591
           Summary: variant allows for creating multiple empty objects at
                    same address
           Product: gcc
           Version: 13.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: barry.revzin at gmail dot com
  Target Milestone: ---

Consider:

#include <variant>
#include <iostream>

struct Empty { ~Empty() {} };
struct Sub : Empty { std::variant<Empty> e; };

int main() {
    Sub v;

    Empty* base = &v;
    Empty* obj = &std::get<Empty>(v.e);

    std::cout
        << "base=" << (void*)base
        << " obj=" << (void*)obj
        << " matches=" << (base == obj)
        << '\n';
}

In C++17 mode on trunk, base and obj have the same address.
In C++20 mode up through 11.4, they have the same address. Since 12.1, they do
not.

If Empty were trivially destructible, they never have the same address.

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

end of thread, other threads:[~2023-11-19 21:48 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-17 16:02 [Bug libstdc++/112591] New: variant allows for creating multiple empty objects at same address barry.revzin at gmail dot com
2023-11-17 16:53 ` [Bug libstdc++/112591] " barry.revzin at gmail dot com
2023-11-17 17:21 ` redi at gcc dot gnu.org
2023-11-19 21:48 ` 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).