This is an archive of the discontinued LLVM Phabricator instance.

[clang] [PR49736] [C++2b] Correctly reject lambdas with requires clause and no parameter list
ClosedPublic

Authored by curdeius on Mar 29 2021, 1:27 AM.

Details

Summary

This fixes http://llvm.org/PR49736 caused by implementing http://wg21.link/P1102 (https://reviews.llvm.org/rG0620e6f4b76a9725dbd82454d58c5a68a7e47074), by correctly allowing requires-clause only:

  1. directly after template-parameter-list
  2. after lambda-specifiers iff parameter-declaration-clause is present (2nd kind of lambda-declarator)

Diff Detail

Event Timeline

curdeius requested review of this revision.Mar 29 2021, 1:27 AM
curdeius created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptMar 29 2021, 1:27 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
aaron.ballman added inline comments.Mar 29 2021, 7:27 AM
clang/lib/Parse/ParseExprCXX.cpp
1435

Rather than add this in both branches, I'd say to hoist it out of the branches and put it after the else if below (before the declaration of ScopeFlags).

curdeius added inline comments.Mar 29 2021, 8:21 AM
clang/lib/Parse/ParseExprCXX.cpp
1435

True. Will do soon.

curdeius updated this revision to Diff 333910.Mar 29 2021, 9:36 AM
  • Hoist common code.
curdeius marked an inline comment as done.Mar 29 2021, 9:37 AM

Mostly looks good, just a few things with the tests.

clang/test/Parser/cxx-concepts-requires-clause.cpp
160–162

This warning seems less than ideal (same issue happens below).

clang/test/Parser/cxx2a-template-lambdas.cpp
15

You should spell out the full diagnostic the first time it's used in a file.

17

This seems grammatically valid to me, was there a reason for the // ??

33–36

It seems odd to warn the user about use of an extension they're not really using, but I don't think this is strictly wrong as opposed to just not being ideal. I don't think this will be trivial to improve the behavior, so I think it's fine for the moment.

Only a nit, please go ahead once Aaron is happy :)

clang/test/Parser/cxx2a-template-lambdas.cpp
25–29

I'd find these examples easier to read with a space between true and ().

curdeius updated this revision to Diff 334064.Mar 30 2021, 12:32 AM
curdeius marked 2 inline comments as done.
  • Clean up tests.
  • Fix grammar comment.
clang/test/Parser/cxx2a-template-lambdas.cpp
17

Ooops, a WIP remnant.

25–29

I've just clang-formatted the code. Isn't it the way to go?
I can format manually if desired though.

33–36

I agree that having an error and a warning is strange, but IMO the extension is used here.
Without the extension, you couldn't have noexcept without ().

curdeius updated this revision to Diff 334075.Mar 30 2021, 1:48 AM
  • Rebase to fix CI.
aaron.ballman accepted this revision.Mar 30 2021, 4:43 AM

LGTM aside from the test case commenting nit. Thank you!

clang/test/Parser/cxx2a-template-lambdas.cpp
17

Please spell out the full diagnostic wording in this instance.

This revision is now accepted and ready to land.Mar 30 2021, 4:43 AM
This revision was landed with ongoing or failed builds.Mar 30 2021, 4:54 AM
This revision was automatically updated to reflect the committed changes.
curdeius marked 2 inline comments as done.Mar 30 2021, 4:55 AM