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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2021-08-18
     Ever confirmed|0                           |1
           Keywords|                            |link-failure

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
In C++17 the declaration in the class body is an inline variable, so
GCC emits a definition using the STB_GNU_UNIQUE binding, which means
that multiple definitions are allowed and the linker will only keep
one. However, that seems to only work if all definitions use that
binding. In this case, the C++11 lib.o object has a non-weak
non-STB_GNU_UNIQUE definition, which cannot be merged with the
STB_GNU_UNIQUE definition.

Clang's weak definition can be ignored by the linker in favour of the
non-weak definition from the C++11 object.

I'm not sure if GCC should change, or if the linker should be changed
to permit a single non-weak non-UNIQUE definition to be merged with
zero or more UNIQUE definitions. As a workaround you can compile the
C++17 code with -fno-gnu-unique so that GCC uses a weak symbol, but
that isn't a good solution in general (the unique binding exists for
good reasons).

Reply via email to