This is an archive of the discontinued LLVM Phabricator instance.

[libc++] Fix the noexceptness of __decay_copy.
ClosedPublic

Authored by Quuxplusone on Dec 13 2021, 12:02 PM.

Details

Reviewers
ldionne
zoecarver
Group Reviewers
Restricted Project
Commits
rG4dd901f4d3aa: [libc++] Fix the noexceptness of __decay_copy.
Summary

When a was an array type, __decay_copy(a) was incorrectly marking itself noexcept(false), because it is false that int[10] is nothrow convertible to int[10] (in fact it is not convertible at all).

We have no tests explicitly for __decay_copy, but the new ranges::begin and ranges::end tests fail before this patch.

Diff Detail

Event Timeline

Quuxplusone requested review of this revision.Dec 13 2021, 12:02 PM
Quuxplusone created this revision.
Herald added 1 blocking reviewer(s): Restricted Project. · View Herald TranscriptDec 13 2021, 12:02 PM
ldionne accepted this revision.Dec 13 2021, 12:07 PM
This revision is now accepted and ready to land.Dec 13 2021, 12:07 PM
libcxx/include/__utility/decay_copy.h
27

Actually, it occurs to me that several things are probably wrong here and we should just fix them all at once.

  • We don't care about convertible but rather constructible.
  • We should be returning decay_t<_Tp>(static_cast<_Tp&&>(__t)), not simply static_cast<_Tp&&>(__t).
  • We should be noexcept'ing on the same expression.
  • We should just go ahead and make this a full "write it three times" function, so that __decay_copy(mymutex) SFINAEs away instead of pretending it exists and then hard-erroring during instantiation.
  • In C++23, DECAY_COPY is changing over to auto(x), which doesn't call move constructors when you pass it a prvalue, so we'll need something else anyway. How about we just make a macro like this?
#if PRESENT_DAY
 #define _LIBCPP_DECAY_COPY(x) static_cast<typename decay<decltype((x))>::type>(x)
#else
 #define _LIBCPP_DECAY_COPY(x) auto(x)
#endif

and replace all our usages throughout the codebase right now?

I have a vested interest because D115607 adds a ton of __decay_copy calls. :)

ldionne added inline comments.Dec 13 2021, 12:22 PM
libcxx/include/__utility/decay_copy.h
27

http://eel.is/c++draft/expos.only.func#lib:decay-copy is pretty clear on what it's doing. The change from convertible-to to constructible-from seems like a functional change to me.

Is this function somehow not implementing the exposition-only function I linked? If not, you know what I'm going to say. It might be boring, but we're not here to change the design of the standard, we're here to implement it.