public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "pinskia at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug libstdc++/111089] ODR violation warning in std::variant implementation when linking(LTO) C++20 and C++17 TUs
Date: Mon, 21 Aug 2023 18:57:41 +0000	[thread overview]
Message-ID: <bug-111089-4-IbUc2bksJ5@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-111089-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
libstdc++'s c++20 version of _Uninitialized:
      struct _Empty_byte { };

      union {
 _Empty_byte _M_empty;
 _Type _M_storage;
      };

c++17 version:
      __gnu_cxx::__aligned_membuf<_Type> _M_storage;


That is techincally a ODR violation ...


How to reproduce using regular sources (rather than preprocessed sources).
main.cc:
```
#include <variant>
#include <string>
#include <cstdint>

void test(std::variant<std::string, std::uint32_t> id);

int main()
{
    test("123");
}
```
t.cc:
```
#include <variant>
#include <string>
#include <cstdint>


void test(std::variant<std::string, std::uint32_t> id)
{
    __builtin_printf("%d\n", (int)(id.index()));
}
```

$ ~/upstream-gcc/bin/g++ t.cc -std=gnu++20 -c -flto
$ ~/upstream-gcc/bin/g++ main.cc -std=gnu++17 -c -flto
$ ~/upstream-gcc/bin/g++ main.o t.o   -flto
main.cc:5:6: warning: ‘test’ violates the C++ One Definition Rule [-Wodr]
    5 | void test(std::variant<std::string, std::uint32_t> id);
      |      ^
t.cc:6:6: note: type mismatch in parameter 1
    6 | void test(std::variant<std::string, std::uint32_t> id)
      |      ^
/home/apinski/upstream-gcc/include/c++/14.0.0/variant:1337:11: note: type
‘struct variant’ itself violates the C++ One Definition Rule
 1337 |     class variant
      |           ^
t.cc:6:6: note: ‘test’ was previously declared here
    6 | void test(std::variant<std::string, std::uint32_t> id)
      |      ^

      reply	other threads:[~2023-08-21 18:57 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-21 12:00 [Bug c++/111089] New: " damian.jarek93 at gmail dot com
2023-08-21 18:57 ` pinskia at gcc dot gnu.org [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-111089-4-IbUc2bksJ5@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).