From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 4085A3830B4C; Mon, 21 Aug 2023 12:00:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4085A3830B4C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1692619243; bh=y5aG36ow4Cqa/sbaJr2K1vPtQZ8m37hlnzaCrXMl3KQ=; h=From:To:Subject:Date:From; b=yaVMUbwg0lGrjW8eDuUUd11YTGJFP3scrb0ErNsOBk8YUnSTo4jKnkwbNp/ZxTOVm bSH5DT/qEsGU4M82OtDmaQOiWG6aScYm6kfu+C91mBrOqKh9jdT6zsZLuycEx8sh5Z IkX30hQ/+BLA8lmUixvxyZJZU9og3P5HofhsAWuw= From: "damian.jarek93 at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/111089] New: ODR violation warning in std::variant implementation when linking(LTO) C++20 and C++17 TUs Date: Mon, 21 Aug 2023 12:00:42 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 12.3.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: damian.jarek93 at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone attachments.created Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D111089 Bug ID: 111089 Summary: ODR violation warning in std::variant implementation when linking(LTO) C++20 and C++17 TUs Product: gcc Version: 12.3.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: damian.jarek93 at gmail dot com Target Milestone: --- Created attachment 55770 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=3D55770&action=3Dedit ii files of a minimal example that reproduces the issue When 2 TUs are LTO-linked, g++ complains about an ODR violation in std::variant's implementation: /usr/bin/g++-12 -flto -Wall -Wextra -g -flto=3Dauto -fno-fat-lto-objects CMakeFiles/main.dir/main.cpp.o -o main libcxx17-lib.a=20 /usr/include/c++/12/variant:244:12: note: type 'struct _Uninitialized' itse= lf violates the C++ One Definition Rule 244 | struct _Uninitialized<_Type, false> | ^ /usr/include/c++/12/variant:378:11: note: type 'union _Variadic_union' itse= lf violates the C++ One Definition Rule 378 | union _Variadic_union<_First, _Rest...> | ^ /workspaces/odr-bug-repro/cxx17.hpp:8:6: warning: 'test' violates the C++ O= ne Definition Rule [-Wodr] 8 | void test(std::variant id); | ^ /workspaces/odr-bug-repro/cxx17.cpp:5:6: note: type mismatch in parameter 1 5 | void test(std::variant id) | ^ /usr/include/c++/12/variant:1336:11: note: type 'struct variant' itself violates the C++ One Definition Rule 1336 | class variant | ^ /workspaces/odr-bug-repro/cxx17.cpp:5:6: note: 'test' was previously declar= ed here 5 | void test(std::variant id) |=20 The function 'void test(std::variant id)' must = be=20 defined in a TU compiled with -std=3Dgnu++17 and called in a TU compiled wi= th=20 -std=3Dgnu++20. Complete command line that reproduces the issue: /usr/bin/g++-12 -std=3Dgnu++20 -flto -Wall -Wextra -g -o main.cpp.o -c mai= n.cpp /usr/bin/g++-12 -std=3Dgnu++17 -flto -Wall -Wextra -g -o cxx17.cpp.o -c cxx17.cpp /usr/bin/g++-12 -flto -Wall -Wextra -g -flto=3Dauto -fno-fat-lto-objects main.cpp.o cxx17.cpp.o -o main=20 g++ version: Using built-in specs. COLLECT_GCC=3Dg++-12 COLLECT_LTO_WRAPPER=3D/usr/lib/gcc/x86_64-linux-gnu/12/lto-wrapper OFFLOAD_TARGET_NAMES=3Dnvptx-none:amdgcn-amdhsa OFFLOAD_TARGET_DEFAULT=3D1 Target: x86_64-linux-gnu Configured with: ../src/configure -v --with-pkgversion=3D'Ubuntu 12.3.0-1ubuntu1~22.04' --with-bugurl=3Dfile:///usr/share/doc/gcc-12/README.= Bugs --enable-languages=3Dc,ada,c++,go,d,fortran,objc,obj-c++,m2 --prefix=3D/usr --with-gcc-major-version-only --program-suffix=3D-12 --program-prefix=3Dx86_64-linux-gnu- --enable-shared --enable-linker-build-= id --libexecdir=3D/usr/lib --without-included-gettext --enable-threads=3Dposix --libdir=3D/usr/lib --enable-nls --enable-clocale=3Dgnu --enable-libstdcxx-= debug --enable-libstdcxx-time=3Dyes --with-default-libstdcxx-abi=3Dnew --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --enable-libphobos-checking=3Drelea= se --with-target-system-zlib=3Dauto --enable-objc-gc=3Dauto --enable-multiarch --disable-werror --enable-cet --with-arch-32=3Di686 --with-abi=3Dm64 --with-multilib-list=3Dm32,m64,mx32 --enable-multilib --with-tune=3Dgeneric --enable-offload-targets=3Dnvptx-none=3D/build/gcc-12-ALHxjy/gcc-12-12.3.0/= debian/tmp-nvptx/usr,amdgcn-amdhsa=3D/build/gcc-12-ALHxjy/gcc-12-12.3.0/deb= ian/tmp-gcn/usr --enable-offload-defaulted --without-cuda-driver --enable-checking=3Drelease --build=3Dx86_64-linux-gnu --host=3Dx86_64-linux-gnu --target=3Dx86_64-linu= x-gnu Thread model: posix Supported LTO compression algorithms: zlib zstd gcc version 12.3.0 (Ubuntu 12.3.0-1ubuntu1~22.04) I also tested this bug with g++ 13.1.0 and is still present there, although the warning is slightly less verbose.=