This is an archive of the discontinued LLVM Phabricator instance.

[libc++] Fix ODR violation with placeholders
ClosedPublic

Authored by ldionne on Apr 26 2023, 1:43 PM.

Details

Reviewers
philnik
Group Reviewers
Restricted Project
Commits
rG77ac36547a2d: [libc++] Fix ODR violation with placeholders
Summary

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.

Diff Detail

Event Timeline

ldionne created this revision.Apr 26 2023, 1:43 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 26 2023, 1:43 PM
ldionne requested review of this revision.Apr 26 2023, 1:43 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 26 2023, 1:43 PM
Herald added a reviewer: Restricted Project. · View Herald Transcript
ldionne added inline comments.
libcxx/test/std/utilities/function.objects/bind/func.bind/func.bind.place/placeholders.pass.cpp
56–57

This is added test coverage.

philnik accepted this revision.Apr 26 2023, 1:50 PM
philnik added a subscriber: philnik.

IMO it would be nice to have them inline constexpr at some point, but I'm fine with this as a bug fix. Anything else should be evaluated separately.

This revision is now accepted and ready to land.Apr 26 2023, 1:50 PM
This revision was landed with ongoing or failed builds.Apr 27 2023, 7:57 AM
This revision was automatically updated to reflect the committed changes.