This is an archive of the discontinued LLVM Phabricator instance.

Constrain function assignment operator (2574)
ClosedPublic

Authored by zoecarver on Jun 5 2019, 12:53 PM.

Details

Reviewers
mclow.lists
ldionne
EricWF
Group Reviewers
Restricted Project
Summary

This patch fixes issue 2574.

Event Timeline

zoecarver created this revision.Jun 5 2019, 12:53 PM
zoecarver marked an inline comment as done.Jun 5 2019, 12:54 PM
zoecarver added inline comments.
test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F_assign.pass.cpp
128 ↗(On Diff #203232)

Is it okay to allow assignment of functions with return types that are convertible to each other? The issue says:

Callable (C++14 §20.9.11.2) for argument types ArgTypes... and return type R.

ldionne requested changes to this revision.Jun 5 2019, 2:25 PM

Thanks for working on this.

include/functional
2189 ↗(On Diff #203232)

Here.

2231 ↗(On Diff #203232)

I think this should just be _EnableIfCallable<typename decay<_Fp>::type>, since we already add the reference inside __callable above.

Alternatively, I think it would be even better to NOT add the reference inside __callable, and instead do it when we call _EnableIfCallable.

test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F_assign.pass.cpp
128 ↗(On Diff #203232)

Callable seems to allow implicit conversions to the return type, so I think that's OK. However, A is not convertible to int (or vice-versa), so I think your test is correct as-is. You could also test that a F1 can't be assigned to a F2.

This revision now requires changes to proceed.Jun 5 2019, 2:25 PM
zoecarver marked an inline comment as done.Jun 5 2019, 2:32 PM
zoecarver added inline comments.
include/functional
2231 ↗(On Diff #203232)

Good catch. I will remove the reference here. If you think it would be better, I can make another patch to update all instances of _EnableIfCallable.

ldionne added inline comments.Jun 5 2019, 2:38 PM
include/functional
2231 ↗(On Diff #203232)

I would update this patch as suggested.

zoecarver marked an inline comment as done.Jun 5 2019, 2:49 PM
zoecarver added inline comments.
include/functional
2231 ↗(On Diff #203232)

Do you want me to update all three times _EnableIfCallable is used, in this patch (that's fine, just checking)?

zoecarver updated this revision to Diff 232997.Dec 9 2019, 8:58 PM
zoecarver edited the summary of this revision. (Show Details)

Address @ldionne comments

Herald added a project: Restricted Project. · View Herald TranscriptDec 9 2019, 8:58 PM
Herald added a subscriber: christof. · View Herald Transcript
ldionne accepted this revision.May 12 2020, 8:16 AM

LGTM. It would be great if you could provide a patch that moves adding the reference outside of __callable, such that the code becomes: _EnableIfCallable<typename decay<_Fp>::type&> (notice the added reference here). You'd have to look at other usages of _EnableIfCallable too. Note that some usages of _EnableIfCallable correspond to places in the Standard where the term Lvalue-Callable is used. We could consider adding a LValueCallable trait to mirror that. Just a suggestion.

This revision is now accepted and ready to land.May 12 2020, 8:16 AM
Herald added a reviewer: Restricted Project. · View Herald TranscriptMay 12 2020, 8:16 AM
This revision now requires review to proceed.May 12 2020, 8:16 AM
ldionne accepted this revision.May 12 2020, 8:17 AM
This revision is now accepted and ready to land.May 12 2020, 8:17 AM

It would be great if you could provide a patch that moves adding the reference outside of __callable.

Sounds good. Will do.