[clang] [Clang][Sema] Diagnose use of template keyword in declarative nested-name-specifiers (PR #78595)

via cfe-commits cfe-commits at lists.llvm.org
Thu Jan 18 07:11:45 PST 2024


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff 77d21e758ea9665631b211abc0e424d7a7c44989 8a5ad668768ed97466f195e85308b6a15910c38a -- clang/test/CXX/temp/temp.names/p5.cpp clang/include/clang/AST/TypeLoc.h clang/include/clang/Sema/Sema.h clang/lib/Sema/SemaDecl.cpp clang/lib/Sema/SemaDeclCXX.cpp clang/lib/Sema/SemaTemplate.cpp clang/lib/Sema/TreeTransform.h clang/test/CXX/drs/dr23xx.cpp clang/test/CXX/drs/dr7xx.cpp clang/test/CXX/temp/temp.decls/temp.class/temp.mem.func/p1.cpp clang/test/CXX/temp/temp.spec/part.spec.cpp clang/test/SemaCXX/static-assert.cpp clang/test/SemaTemplate/class-template-spec.cpp
``````````

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index f6b5b65bc8..cfa5198185 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -6264,7 +6264,8 @@ bool Sema::DiagnoseClassNameShadow(DeclContext *DC,
 ///
 /// \param Loc The location of the name of the entity being declared.
 ///
-/// \param IsMemberSpecialization Whether we are declaring a member specialization.
+/// \param IsMemberSpecialization Whether we are declaring a member
+/// specialization.
 ///
 /// \param TemplateId The template-id, if any.
 ///
@@ -6353,7 +6354,7 @@ bool Sema::diagnoseQualifiedDeclaration(CXXScopeSpec &SS, DeclContext *DC,
   //   nested-name-specifier.
   if (TemplateId && TemplateId->TemplateKWLoc.isValid()) {
     Diag(Loc, diag::err_template_in_declarative_nns)
-         << FixItHint::CreateRemoval(TemplateId->TemplateKWLoc);
+        << FixItHint::CreateRemoval(TemplateId->TemplateKWLoc);
   }
 
   NestedNameSpecifierLoc SpecLoc(SS.getScopeRep(), SS.location_data());
@@ -6453,10 +6454,11 @@ NamedDecl *Sema::HandleDeclarator(Scope *S, Declarator &D,
     if (!D.getDeclSpec().isFriendSpecified()) {
       TemplateIdAnnotation *TemplateId =
           D.getName().getKind() == UnqualifiedIdKind::IK_TemplateId
-          ? D.getName().TemplateId : nullptr;
-      if (diagnoseQualifiedDeclaration(
-              D.getCXXScopeSpec(), DC, Name, D.getIdentifierLoc(),
-              TemplateId, /*IsMemberSpecialization=*/false)) {
+              ? D.getName().TemplateId
+              : nullptr;
+      if (diagnoseQualifiedDeclaration(D.getCXXScopeSpec(), DC, Name,
+                                       D.getIdentifierLoc(), TemplateId,
+                                       /*IsMemberSpecialization=*/false)) {
         if (DC->isRecord())
           return nullptr;
 
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index f8b2e3f805..0cf9cb68ee 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -3624,9 +3624,11 @@ Sema::ActOnCXXMemberDeclarator(Scope *S, AccessSpecifier AS, Declarator &D,
       if (DeclContext *DC = computeDeclContext(SS, false)) {
         TemplateIdAnnotation *TemplateId =
             D.getName().getKind() == UnqualifiedIdKind::IK_TemplateId
-            ? D.getName().TemplateId : nullptr;
+                ? D.getName().TemplateId
+                : nullptr;
         diagnoseQualifiedDeclaration(SS, DC, Name, D.getIdentifierLoc(),
-                                     TemplateId, /*IsMemberSpecialization=*/false);
+                                     TemplateId,
+                                     /*IsMemberSpecialization=*/false);
       } else {
         Diag(D.getIdentifierLoc(), diag::err_member_qualification)
           << Name << SS.getRange();
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index 95fe29eeab..5858fdfec3 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -1894,7 +1894,8 @@ DeclResult Sema::CheckClassTemplate(
 
     if (TUK != TUK_Friend && TUK != TUK_Reference)
       diagnoseQualifiedDeclaration(SS, SemanticContext, Name, NameLoc,
-                                   /*TemplateId-*/nullptr, /*IsMemberSpecialization*/false);
+                                   /*TemplateId-*/ nullptr,
+                                   /*IsMemberSpecialization*/ false);
 
     LookupQualifiedName(Previous, SemanticContext);
   } else {
@@ -8778,8 +8779,7 @@ DeclResult Sema::ActOnClassTemplateSpecialization(
     if (TUK != TUK_Reference && TUK != TUK_Friend &&
         diagnoseQualifiedDeclaration(SS, ClassTemplate->getDeclContext(),
                                      ClassTemplate->getDeclName(),
-                                     TemplateNameLoc,
-                                     &TemplateId,
+                                     TemplateNameLoc, &TemplateId,
                                      /*IsMemberSpecialization=*/false))
       return true;
   }

``````````

</details>


https://github.com/llvm/llvm-project/pull/78595


More information about the cfe-commits mailing list