This is an archive of the discontinued LLVM Phabricator instance.

[libc++] Match declaration for non-member function std::swap(std::packaged_task) with what standard specify
ClosedPublic

Authored by jasonliu on Mar 22 2021, 12:20 PM.

Details

Summary

Standard specifies:

template<class R, class... ArgTypes>
  void swap(packaged_task<R(ArgTypes...)>& x, packaged_task<R(ArgTypes...)>& y) noexcept;

Diff Detail

Event Timeline

jasonliu requested review of this revision.Mar 22 2021, 12:20 PM
jasonliu created this revision.
Quuxplusone requested changes to this revision.Mar 22 2021, 12:50 PM
Quuxplusone added a subscriber: Quuxplusone.

Hard no. std::swap is not meant to be called with explicit template arguments (and especially not random arguments like <double, int, char>).
Is this an XY problem?

This revision now requires changes to proceed.Mar 22 2021, 12:50 PM
ldionne requested changes to this revision.Mar 22 2021, 1:07 PM
ldionne added a subscriber: ldionne.

Agreed with Arthur about the fact that it's not supposed to be called that way. However, the Standard does specify it as being swap(packaged_task<C(A...)>): http://eel.is/c++draft/futures.task#nonmembers-1. So I'm fine with the change as decreasing distance from the Standard, but I think we should *not* add a test.

jasonliu updated this revision to Diff 332419.Mar 22 2021, 2:08 PM
jasonliu retitled this revision from [libc++] non-member function std::swap(std::packaged_task) should be able to take explicit template argument to [libc++] Match declaration for non-member function std::swap(std::packaged_task) with what standard specify.
jasonliu edited the summary of this revision. (Show Details)

Got it. Make sense. I removed the test case in case we want to have the declaration be more like what standard have in the text.

ldionne accepted this revision.Mar 23 2021, 7:58 AM

@Quuxplusone Do you have a problem with this?

Quuxplusone accepted this revision.Mar 23 2021, 8:06 AM

Sure; I'm still uncomfortable with making this change to enable the discouraged use-case (even without the test). But there's no real chance anyone would ever ask to change the code back to the old version.

This revision is now accepted and ready to land.Mar 23 2021, 8:06 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 24 2021, 3:34 PM