[libc++] Fix ODR violation with placeholders
authorLouis Dionne <ldionne.2@gmail.com>
Wed, 26 Apr 2023 20:35:13 +0000 (16:35 -0400)
committerLouis Dionne <ldionne.2@gmail.com>
Thu, 27 Apr 2023 14:57:15 +0000 (10:57 -0400)
commit77ac36547a2d15dc465d723179ce7047a59583ce
treecc11d054ed32e16bbef79cdf9d1b2a0ba96abd9c
parent6d0ca5ae4c5ada004934c56bbe4d7c5db765a209
[libc++] Fix ODR violation with placeholders

In D145589, we made the std::bind placeholders inline constexpr to
satisfy C++17. It turns out that this causes ODR violations since the
shared library provides strong definitions for those placeholders, and
the linker on Windows actually complains about this.

Fortunately, C++17 only encourages implementations to use `inline constexpr`,
it doesn't force them. So instead, we unconditionally define the placeholders
as `extern const`, which avoids the ODR violation and is indistinguishable
from `inline constexpr` for most purposes, since the placeholders are
empty types anyway.

Note that we could also go back to the pre-D145589 state of defining them
as non-inline constexpr variables in C++17, however that is definitely
non-conforming since that means the placeholders have different addresses
in different TUs. This is all a bit pedantic, but all in all I feel that
`extern const` provides the best bang for our buck, and I can't really
find any downsides to that solution.

Differential Revision: https://reviews.llvm.org/D149292
libcxx/include/__functional/bind.h
libcxx/test/std/utilities/function.objects/bind/func.bind/func.bind.place/placeholders.pass.cpp