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 via email to