libstdc++: Fix multiple definitions of std::exception_ptr functions [PR 97729]
authorJonathan Wakely <jwakely@redhat.com>
Thu, 5 Nov 2020 16:19:15 +0000 (16:19 +0000)
committerJonathan Wakely <jwakely@redhat.com>
Thu, 5 Nov 2020 18:01:25 +0000 (18:01 +0000)
commit710508c7b1a2c8e1d75d4c4f1ac79473dbf2b2bb
tree8a346f958091efd5ee88f27e56d794a817206535
parent50b840ac5e1d6534e345c3fee9a97ae45ced6bc7
libstdc++: Fix multiple definitions of std::exception_ptr functions [PR 97729]

This fixes some multiple definition errors caused by the changes for
PR libstdc++/90295. The previous solution for inlining the members of
std::exception_ptr but still exporting them from the library was to
suppress the 'inline' keyword on those functions when compiling
libsupc++/eh_ptr.cc, so they get defined in that file. That produces ODR
violations though, because there are now both inline and non-inline
definitions in the library, due to the use of std::exception_ptr in
other files sucg as src/c++11/future.cc.

The new solution is to define all the relevant members as 'inline'
unconditionally, but use __attribute__((used)) to cause definitions to
be emitted in libsupc++/eh_ptr.cc as before. This doesn't quite work
however, because PR c++/67453 means the attribute is ignored on
constructors and destructors. As a workaround, the old solution
(conditionally inline) is still used for those members, but they are
given the always_inline attribute so that they aren't emitted in
src/c++11/future.o as inline definitions.

libstdc++-v3/ChangeLog:

PR libstdc++/97729
* include/std/future (__basic_future::_M_get_result): Use
nullptr for null pointer constant.
* libsupc++/eh_ptr.cc (operator==, operator!=): Remove
definitions.
* libsupc++/exception_ptr.h (_GLIBCXX_EH_PTR_USED): Define
macro to conditionally add __attribute__((__used__)).
(operator==, operator!=, exception_ptr::exception_ptr())
(exception_ptr::exception_ptr(const exception_ptr&))
(exception_ptr::~exception_ptr())
(exception_ptr::operator=(const exception_ptr&))
(exception_ptr::swap(exception_ptr&)): Always define as
inline. Add macro to be conditionally "used".
libstdc++-v3/include/std/future
libstdc++-v3/libsupc++/eh_ptr.cc
libstdc++-v3/libsupc++/exception_ptr.h