[clang] [Clang][Sema] Diagnose declarative nested-name-specifiers naming alias templates (PR #80842)
Erich Keane via cfe-commits
cfe-commits at lists.llvm.org
Tue Feb 6 07:17:39 PST 2024
================
@@ -6295,22 +6297,36 @@ bool Sema::diagnoseQualifiedDeclaration(CXXScopeSpec &SS, DeclContext *DC,
<< FixItHint::CreateRemoval(TemplateId->TemplateKWLoc);
NestedNameSpecifierLoc SpecLoc(SS.getScopeRep(), SS.location_data());
- while (SpecLoc.getPrefix()) {
+ do {
if (SpecLoc.getNestedNameSpecifier()->getKind() ==
NestedNameSpecifier::TypeSpecWithTemplate)
Diag(Loc, diag::ext_template_after_declarative_nns)
<< FixItHint::CreateRemoval(
SpecLoc.getTypeLoc().getTemplateKeywordLoc());
- SpecLoc = SpecLoc.getPrefix();
- }
- // C++11 [dcl.meaning]p1:
- // [...] "The nested-name-specifier of the qualified declarator-id shall
- // not begin with a decltype-specifer"
- if (isa_and_nonnull<DecltypeType>(
- SpecLoc.getNestedNameSpecifier()->getAsType()))
- Diag(Loc, diag::err_decltype_in_declarator)
- << SpecLoc.getTypeLoc().getSourceRange();
+ if (const Type *T = SpecLoc.getNestedNameSpecifier()->getAsType()) {
+ if (const auto *TST = T->getAsAdjusted<TemplateSpecializationType>()) {
+ // C++23 [expr.prim.id.qual]p3:
+ // [...] If a nested-name-specifier N is declarative and has a
+ // simple-template-id with a template argument list A that involves a
+ // template parameter, let T be the template nominated by N without A.
+ // T shall be a class template.
+ if (TST->isDependentType() && TST->isTypeAlias())
+ Diag(Loc, diag::ext_alias_template_in_declarative_nns)
+ << SpecLoc.getLocalSourceRange();
+ } else if (T->isDecltypeType()) {
+ // C++23 [expr.prim.id.qual]p2:
+ // [...] A declarative nested-name-specifier shall not have a
+ // decltype-specifier.
+ //
+ // FIXME: This wording appears to be defective, as it does not
----------------
erichkeane wrote:
Cool, please add that reference to the comment/FIXME. Also, @Endilll might want to check it out too!
https://github.com/llvm/llvm-project/pull/80842
More information about the cfe-commits
mailing list