This is an archive of the discontinued LLVM Phabricator instance.

[libcxx] LWG2993: reference_wrapper<T> conversion from T&&
AbandonedPublic

Authored by ldionne on Nov 20 2017, 10:24 AM.

Details

Summary

Implement LWG2993, reference_wrapper<T> conversion from T&&.

The currently failing test is due to https://bugs.llvm.org/show_bug.cgi?id=35332.

Diff Detail

Event Timeline

K-ballo created this revision.Nov 20 2017, 10:24 AM
EricWF requested changes to this revision.Nov 20 2017, 11:41 AM

I would much rather take this change in all dialects except for C++03.

include/__functional_base
398

The __void_t isn't necessary here. Plus I think we can be clever and write this condition as:

bool _IsNoexcept = noexcept(<expr>)

And then we can re-use _Noexcept to make the function conditionally noexcept instead of duplicating the expression.

This revision now requires changes to proceed.Nov 20 2017, 11:41 AM

Also, you're lacking tests for noexcept and the deduction guide.

tcanens added inline comments.
include/__functional_base
377

I'd make these member functions of a class template, to avoid having to reason about partial ordering in overload resolution.

K-ballo updated this revision to Diff 123679.Nov 20 2017, 4:04 PM
K-ballo edited edge metadata.

Addressed review comments. Added tests for SFINAE, noexcept, deduction guide.

tcanens added inline comments.Nov 20 2017, 7:48 PM
include/__functional_base
396

Is it safe to do this when we are using _NOEXCEPT_ in the next line?

EricWF added inline comments.Nov 21 2017, 12:04 AM
include/__functional_base
396

It should be. The noexcept condition should only be evaluated *as needed* for functions selected by overload resolution. i.e. The noexcept condition is only considered on well-formed functions. And this function is only well-formed if _IsNothrow is well formed.

If IsNothrow is ill-formed, it will prevent the functions noexcept specifier from ever being evaluated.

tcanens added inline comments.Nov 21 2017, 12:46 AM
include/__functional_base
396

My point is that the use of macro-ized _NOEXCEPT_ suggests that we are supporting compilers that doesn't have noexcept-specifications. Given that, can we then use the noexcept operator here?

EricWF added inline comments.Nov 21 2017, 1:29 AM
include/__functional_base
396

Ah, I see!

The _NOEXCEPT_ macro is a holdover from the C++03/C++11 era. This code expects a C++11 conformant compiler, and hence expects noexcept to work as a non-buggy feature-complete C++11 construct.

Much in the same way the current (and previous) code expects C++11 template aliases, default function template arguments, decltype, ect. to work.

K-ballo updated this revision to Diff 123813.Nov 21 2017, 8:59 AM

Full context diff.

EricWF requested changes to this revision.Nov 22 2017, 11:37 AM
EricWF added inline comments.
include/__functional_base
396

So I need to backpeddel about using noexcept in the SFINAE instead of decltype. I forgot that noexcept specifications are evaluated "as-needed", and using it in SFINAE could potentially cause the evaluation of "unneeded" noexcept specifications.

Could we go back to decltype please?

Sorry about that.

test/std/utilities/function.objects/refwrap/refwrap.const/type_conv_ctor.pass.cpp
18

This should probably be // UNSUPPORTED.

This revision now requires changes to proceed.Nov 22 2017, 11:37 AM
K-ballo updated this revision to Diff 124005.Nov 22 2017, 12:46 PM
K-ballo edited edge metadata.

Back to decltype-based SFINAE.

K-ballo updated this revision to Diff 124201.Nov 24 2017, 6:42 AM
K-ballo edited the summary of this revision. (Show Details)

Turn fail test into SFINAE based pass test, mark XFAIL for clang.

EricWF accepted this revision.Jan 24 2018, 4:30 PM

LGTM after addressing inline comments. Do you have commit access? If not, I'll commit once updated.

test/std/utilities/function.objects/refwrap/refwrap.const/type_conv_ctor2.pass.cpp
16

Please change the XFAIL into simply clang since this hasn't been fixed yet, and add a link to the relevant bug in this file.

This revision is now accepted and ready to land.Jan 24 2018, 4:30 PM
mclow.lists accepted this revision.Jan 30 2018, 6:43 AM

Please be sure to update www/cxx2a_status.html to mark 2993 as "Complete".
Other than that, looks good to me! Thanks!

Did this ever get landed? If not, was there a reason?
Note that the synopsis at the top of <functional> also needs to be updated.

ldionne set the repository for this revision to rG LLVM Github Monorepo.Feb 9 2021, 11:39 AM
ldionne added a project: Restricted Project.
Herald added a project: Restricted Project. · View Herald TranscriptFeb 9 2021, 11:39 AM
ldionne commandeered this revision.Feb 9 2021, 11:43 AM
ldionne added a reviewer: K-ballo.
ldionne added a subscriber: ldionne.

This is superseded by D92725, so I'm going to commandeer and abandon this to clear up the review queue. Thanks for your contribution - it seems to me that part of D92725 is actually taken from this patch.

ldionne abandoned this revision.Feb 9 2021, 11:43 AM

Closing as this is superseded by D92725.