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

            Bug ID: 122905
           Summary: ODR warning with C++11 and C++20 std::string use
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: nvinson234 at gmail dot com
  Target Milestone: ---

Created attachment 62932
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=62932&action=edit
example.tar.gz

When linking objects built against mixed C++ standards, g++ issues the
following warning (note: -Werror is also specified, so diagnostic messages say
error):

    a.h:6:13: error: ‘example’ violates the C++ One Definition Rule
[-Werror=odr]
        6 | std::string example();
          |             ^
    a.cc:3:13: note: return value type mismatch
        3 | std::string example()
          |             ^
    a.cc:3:13: note: type ‘struct string’ itself violates the C++ One
Definition Rule
    a.cc:3:13: note: ‘example’ was previously declared here
    lto1: some warnings being treated as errors
    lto-wrapper: fatal error: g++-16 returned 1 exit status
    compilation terminated.
    /usr/lib/gcc/x86_64-pc-linux-gnu/16/../../../../x86_64-pc-linux-gnu/bin/ld:
error: lto-wrapper failed
    collect2: error: ld returned 1 exit status

Steps to reproduce:
1. download example.tar.gz
2. extract archive
3. run driver.sh script
4. observe failure

Additional notes:
g++-16 version: g++-16 (Gentoo 16.0.9999 p, commit
2896409d3014457af03090f2e3bc26e66f2d6381) 16.0.0 20251128 (experimental)
c64308e297a13d0f0e19ec871b5e81348b4da484

When using g++-15 (Gentoo 15.2.1_p20251108-r1 p2) 15.2.1 20251108 the linker
exits successfully.

Warning also appears when linking an object built with c++-17 with one built
with c++-20.

Reply via email to