diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp --- a/clang/lib/Parse/ParseDecl.cpp +++ b/clang/lib/Parse/ParseDecl.cpp @@ -3448,12 +3448,12 @@ continue; } - if (TemplateId && TemplateId->Kind == TNK_Concept_template && - GetLookAheadToken(2).isOneOf(tok::kw_auto, tok::kw_decltype)) { + if (TemplateId && TemplateId->Kind == TNK_Concept_template) { DS.getTypeSpecScope() = SS; - // This is a qualified placeholder-specifier, e.g., ::C auto ... - // Consume the scope annotation and continue to consume the template-id - // as a placeholder-specifier. + // This is probably a qualified placeholder-specifier, e.g., ::C + // auto ... Consume the scope annotation and continue to consume the + // template-id as a placeholder-specifier. Let the next iteration + // diagnose a missing auto. ConsumeAnnotationToken(); continue; } diff --git a/clang/lib/Parse/Parser.cpp b/clang/lib/Parse/Parser.cpp --- a/clang/lib/Parse/Parser.cpp +++ b/clang/lib/Parse/Parser.cpp @@ -1883,31 +1883,25 @@ return ANK_TemplateName; } [[fallthrough]]; + case Sema::NC_Concept: case Sema::NC_VarTemplate: case Sema::NC_FunctionTemplate: case Sema::NC_UndeclaredTemplate: { - // We have a type, variable or function template followed by '<'. - ConsumeToken(); - UnqualifiedId Id; - Id.setIdentifier(Name, NameLoc); - if (AnnotateTemplateIdToken( - TemplateTy::make(Classification.getTemplateName()), - Classification.getTemplateNameKind(), SS, SourceLocation(), Id)) - return ANK_Error; - return ANK_Success; - } - case Sema::NC_Concept: { - UnqualifiedId Id; - Id.setIdentifier(Name, NameLoc); + bool IsConceptName = Classification.getKind() == Sema::NC_Concept; + // We have a template name followed by '<'. Consume the identifier token so + // we reach the '<' and annotate it. if (Next.is(tok::less)) - // We have a concept name followed by '<'. Consume the identifier token so - // we reach the '<' and annotate it. ConsumeToken(); + UnqualifiedId Id; + Id.setIdentifier(Name, NameLoc); if (AnnotateTemplateIdToken( TemplateTy::make(Classification.getTemplateName()), Classification.getTemplateNameKind(), SS, SourceLocation(), Id, - /*AllowTypeAnnotation=*/false, /*TypeConstraint=*/true)) + /*AllowTypeAnnotation=*/!IsConceptName, + /*TypeConstraint=*/IsConceptName)) return ANK_Error; + if (SS.isNotEmpty()) + AnnotateScopeToken(SS, !WasScopeAnnotation); return ANK_Success; } } diff --git a/clang/test/Parser/cxx-template-template-recovery.cpp b/clang/test/Parser/cxx-template-template-recovery.cpp new file mode 100644 --- /dev/null +++ b/clang/test/Parser/cxx-template-template-recovery.cpp @@ -0,0 +1,40 @@ +// RUN: %clang_cc1 -std=c++20 -verify -fsyntax-only %s + +namespace a { + template + concept C1 = true; //expected-note {{here}} + + template + auto V1 = true; //expected-note {{here}} + + namespace b { + template + concept C2 = true; //expected-note {{here}} + + template + auto V2 = true; //expected-note {{here}} + } +} + +template +concept C3 = true; //expected-note {{here}} +template +auto V3 = true; //expected-note {{here}} + +template