This is an archive of the discontinued LLVM Phabricator instance.

[clang] [C++2b] [P1102] Accept lambdas without parameter list ().
ClosedPublic

Authored by curdeius on Mar 11 2021, 9:33 AM.

Diff Detail

Event Timeline

curdeius requested review of this revision.Mar 11 2021, 9:33 AM
curdeius created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptMar 11 2021, 9:33 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
curdeius updated this revision to Diff 329998.Mar 11 2021, 9:37 AM

Revert unintended changes.

Is there something else that I should test?

clang/lib/Parse/ParseExprCXX.cpp
1434

I'm not sure what I should do with LParenLoc and RParenLoc. Any idea?

Harbormaster completed remote builds in B93329: Diff 329998.
curdeius retitled this revision from [C++2b] [P1102] Accept lambdas without parameter list (). to [clang] [C++2b] [P1102] Accept lambdas without parameter list ()..Mar 12 2021, 12:47 AM
aaron.ballman added inline comments.Mar 15 2021, 9:31 AM
clang/lib/Parse/ParseExprCXX.cpp
1432–1433

No need to call this here, it happens from the destructor of ParseScope.

1432–1435

No need to call this here, it happens from the destructor of ParseScope.

1434

I don't know the answer to this, but... do we need a prototype scope at all when there's no parameter list? The old code was doing this, so I don't think this is an issue with your patch per se, more just curiosity whether this is necessary in this case.

1434

What you've done here seems reasonable to me. The SourceLocation for the parens will be invalid, which is the behavior I'd expect when the parens are missing.

clang/test/Parser/cxx2b-lambdas.cpp
23

It'd be handy to test: auto XL3 = []( constexpr mutable constexpr {}; where the parameter list is missing the closing right paren.

curdeius updated this revision to Diff 330901.Mar 16 2021, 1:50 AM
curdeius marked 4 inline comments as done.
  • Add test.
  • Remove unnecessary PrototypeScope.exit().

Thank you for the review Aaron. I hope having addressed your comments so far.
I'm not sure for the prototype scope though.

clang/lib/Parse/ParseExprCXX.cpp
1434

I'm not really familiar with clang (I usually work with other parts of LLVM), but at least in the current implementation (before this patch) the prototype scope englobes the parsing of lambda-specifiers, so I found it logical to keep it the same way.

I think this seems reasonable, but one question I have is: do we want to accept lambdas without parens in older C++ modes as an extension (with suitable compatibility warnings)?

That's my question as well to be honest. I don't know what's the policy on that.
Anyway, it will simplify the code a bit I think.

curdeius planned changes to this revision.Mar 17 2021, 1:51 AM

I've checked and GCC accepts lambdas without parens (but with specifiers) in all standard modes, giving a warning pre-C++2b.
I guess it's reasonable to align the behaviour.
Cf. https://github.com/gcc-mirror/gcc/commit/0f161cc8494cf7283a16fa9ebbcf8fd121bab68d#diff-e668c6c0533673af02f98ed35505230e0f6abdcc4f4814642ef619c93cadf794R11353-R11360, https://godbolt.org/z/5zK4M6.
I'll do it also then unless somebody opposes.

I've checked and GCC accepts lambdas without parens (but with specifiers) in all standard modes, giving a warning pre-C++2b.
I guess it's reasonable to align the behaviour.
Cf. https://github.com/gcc-mirror/gcc/commit/0f161cc8494cf7283a16fa9ebbcf8fd121bab68d#diff-e668c6c0533673af02f98ed35505230e0f6abdcc4f4814642ef619c93cadf794R11353-R11360, https://godbolt.org/z/5zK4M6.
I'll do it also then unless somebody opposes.

I think that makes sense, thank you for looking into it!

curdeius updated this revision to Diff 331795.Mar 19 2021, 1:41 AM
  • Accept but warn in pre-C++2b mode when lambda is missing '()' and have lambda-specifiers.
  • Fix tests.

I'll fix the formatting with the next update.

clang/lib/Parse/ParseExprCXX.cpp
1444–1460

Is this really needed? May I simplify remove this switch and just have a generic warning message?

aaron.ballman added inline comments.Mar 22 2021, 5:45 AM
clang/lib/Parse/ParseExprCXX.cpp
1444–1460

I think a generic diagnostic would be reasonable. I think lambda without a parameter clause is a C++2b extension would be sufficiently clear.

curdeius updated this revision to Diff 332340.Mar 22 2021, 9:54 AM
  • Use a generic message.
  • Fix formatting.
curdeius marked an inline comment as done.Mar 23 2021, 12:44 AM
curdeius updated this revision to Diff 332558.Mar 23 2021, 1:36 AM
  • Format.
aaron.ballman added inline comments.Mar 23 2021, 6:03 AM
clang/lib/Parse/ParseExprCXX.cpp
1453

I believe you can remove this diagnostic from DiagnosticParseKinds.td now.

clang/test/Parser/cxx-concepts-requires-clause.cpp
161

Because you're touching the end of the file anyway, can you add the newline?

curdeius updated this revision to Diff 332904.Mar 24 2021, 2:19 AM
  • Address review comments (newline + remove diagnostic).
curdeius marked 2 inline comments as done.Mar 24 2021, 2:23 AM
aaron.ballman accepted this revision.Mar 24 2021, 6:12 AM

LGTM, thank you!

This revision is now accepted and ready to land.Mar 24 2021, 6:12 AM
curdeius edited the summary of this revision. (Show Details)Mar 24 2021, 6:25 AM