This is an archive of the discontinued LLVM Phabricator instance.

[clang] Mark lambda-to-function-pointer conversion as noexcept
ClosedPublic

Authored by loskutov on Jan 20 2019, 5:46 PM.

Details

Summary

Starting from C++17, [expr.prim.lambda.closure]p9 requires that "The [lambda to function pointer] conversion function [...] has a non-throwing exception specification".
This commit adds such a specification to the generated conversion functions.
Pre-C++17 standards don't have this requirement; however, it was reflected in DR 1722.
Due to that, the specification is added unconditionally, no matter what standard revision is used.

Issue related: https://bugs.llvm.org/show_bug.cgi?id=40309

Diff Detail

Repository
rC Clang

Event Timeline

loskutov created this revision.Jan 20 2019, 5:46 PM
loskutov retitled this revision from Mark lambda-to-function-pointer conversion as noexcept to [clang] Mark lambda-to-function-pointer conversion as noexcept.Jan 21 2019, 3:42 AM

Pre-C++17 standards don't have this requirement; however, they don't forbid the conversion functions to have this specification either.

This change happened as a result of DR 1722 (http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#1722), so the correct behavior is to treat this as a requirement since the feature was introduced (aka, what you're doing here is correct). You should also update clang/www/cxx_dr_status.html with the change for the DR.

clang/lib/Sema/SemaLambda.cpp
1231–1232

I would update the previous comment rather than add this one. `The conversion function is always const with a non-throwing exception specification." or some such.

loskutov updated this revision to Diff 182779.Jan 21 2019, 5:12 AM

Fixed the comment.

loskutov updated this revision to Diff 182782.Jan 21 2019, 5:38 AM
loskutov marked an inline comment as done.

Uploaded an updated diff instead of a diff-from-previous-diff

loskutov updated this revision to Diff 182783.Jan 21 2019, 5:40 AM
aaron.ballman accepted this revision.Jan 21 2019, 7:15 AM

Aside from the DR status page and a nit with the test's RUN line, this LGTM. Thank you for working on this -- do you need me to commit on your behalf? If so, are you aware of the recent relicensing of the project and intending to contribute under the new license?

clang/test/CXX/expr/expr.prim/expr.prim.lambda/p9.cpp
2

The test can use -std=c++17

This revision is now accepted and ready to land.Jan 21 2019, 7:15 AM
loskutov updated this revision to Diff 182792.Jan 21 2019, 7:38 AM
loskutov edited the summary of this revision. (Show Details)

Reflected the change in cxx_dr_status.html and specified -std=c++17 for the test.

loskutov marked an inline comment as done.Jan 21 2019, 7:43 AM

Yes, I'm not able to commit by myself, so it would be nice if you did that. Apache 2.0 with LLVM Exceptions is fine.

aaron.ballman closed this revision.Jan 21 2019, 8:25 AM

I needed to make some minor alterations to your patch. The CXX DR status page is automatically generated and I didn't remember that. I went and added an additional test case and did the automated DR regeneration. I've commit in r351750, thank you for the patch!