[clang] Reject auto combined with type specifiers in C++ (PR #208552)
Tony Guillot via cfe-commits
cfe-commits at lists.llvm.org
Fri Jul 17 02:32:57 PDT 2026
================
@@ -3860,18 +3862,44 @@ void Parser::ParseDeclarationSpecifiers(
DS.isFriendSpecified()))
goto DoneWithDeclSpec;
+ // If 'auto' is set and we're in a template parameter context, the
+ // identifier is always the parameter name, not a type specifier, so skip
+ // type name lookup to avoid false ambiguity errors.
+ if (DS.getTypeSpecType() == DeclSpec::TST_auto &&
+ DSContext == DeclSpecContext::DSC_template_param) {
+ goto DoneWithDeclSpec;
+ }
+
+ // If 'auto' is set and the next token indicates this identifier is the
+ // declarator-id, stop parsing declaration specifiers before doing type
+ // lookup. Looking up the declarator-id can produce bogus ambiguity errors
+ // when a variable name matches a type brought in by a using-directive.
+ if (DS.getTypeSpecType() == DeclSpec::TST_auto) {
+ Token Next = NextToken();
+ if (Next.isOneOf(tok::equal, tok::l_paren, tok::l_square, tok::amp,
----------------
to268 wrote:
It looks like there is an issue with this patch. I will send a patch to fix the issue.
https://github.com/llvm/llvm-project/pull/208552
More information about the cfe-commits
mailing list