As an extension, accept such lambdas in previous standards with a warning.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
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? |
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. |
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.
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.
- 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? |
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. |
I believe you can remove this diagnostic from DiagnosticParseKinds.td now.