[PATCH] D149276: [Clang] Fix parsing of `(auto(x))`.
Aaron Ballman via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Apr 26 12:09:59 PDT 2023
aaron.ballman added inline comments.
================
Comment at: clang/docs/ReleaseNotes.rst:360
(`#61336 <https://github.com/llvm/llvm-project/issues/61336>`_)
+- Fix parsing of `auto(x)`, when it is surrounded by parenthesese.
----------------
================
Comment at: clang/include/clang/Parse/Parser.h:2655
TPResult TryParseOperatorId();
- TPResult TryParseInitDeclaratorList();
+ TPResult TryParseInitDeclaratorList(bool mayHaveTrailingReturnType = false);
TPResult TryParseDeclarator(bool mayBeAbstract, bool mayHaveIdentifier = true,
----------------
================
Comment at: clang/include/clang/Parse/Parser.h:2663
ImplicitTypenameContext::No);
- TPResult TryParseFunctionDeclarator();
+ TPResult TryParseFunctionDeclarator(bool mayHaveTrailingReturnType = false);
TPResult TryParseBracketDeclarator();
----------------
================
Comment at: clang/lib/Parse/ParseTentative.cpp:237
ConsumeAnnotationToken();
- if (Tok.is(tok::identifier))
+ if (Tok.isOneOf(tok::identifier, tok::kw_auto))
ConsumeToken();
----------------
This smells a bit off to me because of the comments above -- this is trying to parse an elaborated type specifier, and `auto` cannot appear in this position for that case. Can you help me understand what's going on?
================
Comment at: clang/lib/Parse/ParseTentative.cpp:323
+Parser::TPResult
+Parser::TryParseInitDeclaratorList(bool mayHaveTrailingReturnType) {
while (true) {
----------------
================
Comment at: clang/lib/Parse/ParseTentative.cpp:545
// FIXME: A tag definition unambiguously tells us this is an init-statement.
+ bool mayHaveTrailingReturnType = Tok.is(tok::kw_auto);
if (State.update(TryConsumeDeclarationSpecifier()))
----------------
================
Comment at: clang/lib/Parse/ParseTentative.cpp:1416-1417
+ case tok::kw_auto: {
+ if (NextToken().is(tok::l_brace))
+ return TPResult::False;
+ if (NextToken().is(tok::l_paren)) {
----------------
This seems incorrect to me, consider:
```
auto [[clang::annotate_type("test")]] i = 12;
```
https://godbolt.org/z/7Gx3Gb18h
================
Comment at: clang/lib/Parse/ParseTentative.cpp:1418-1420
+ if (NextToken().is(tok::l_paren)) {
+ return TPResult::Ambiguous;
+ }
----------------
================
Comment at: clang/lib/Parse/ParseTentative.cpp:2114
+Parser::TPResult
+Parser::TryParseFunctionDeclarator(bool mayHaveTrailingReturnType) {
// The '(' is already parsed.
----------------
================
Comment at: clang/test/Parser/cxx1z-decomposition.cpp:97
decltype(auto) [b] = s; // expected-error {{cannot be declared with type 'decltype(auto)'}}
- auto ([c]) = s; // expected-error {{cannot be declared with parentheses}}
+ auto ([c]) = s; // expected-error {{'auto' not allowed here}} \
+ // expected-error {{use of undeclared identifier 'c'}} \
----------------
This first diagnostic is incorrect -- `auto` is definitely allowed there, just that the rest of the declaration is nonsense. I think the "use of undeclared identifier" diagnostic is reasonable. The lambda diagnostic is.... interesting.
Any way you can improve this, or is that a slog?
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D149276/new/
https://reviews.llvm.org/D149276
More information about the cfe-commits
mailing list