[clang] [Sema] Propagate preferred_name attribute to existing specializations (PR #186741)

via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 16 01:28:16 PDT 2026


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 origin/main HEAD --extensions cpp -- clang/test/SemaCXX/gh106358.cpp clang/lib/Sema/SemaDeclAttr.cpp --diff_from_common_commit
``````````

:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:

</details>

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

``````````diff
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 0dc9db76c..d36615333 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -1244,20 +1244,21 @@ static void handlePreferredName(Sema &S, Decl *D, const ParsedAttr &AL) {
       auto *PNA = ::new (S.Context) PreferredNameAttr(S.Context, AL, TSI);
       D->addAttr(PNA);
 
-      for(auto *Spec : CTD->specializations()) {
-	 
-	const TypeDecl *TD = static_cast<const TypeDecl *>(Spec);
-	      if (S.Context.hasSameType(S.Context.getTypeDeclType(TD), TSI->getType())) {
-              
-	  {
- 		for (auto *R : Spec->redecls()) {
-            if (!R->hasAttr<PreferredNameAttr>())
-              R->addAttr(PNA->clone(S.Context));
-	  }
-	}
+      for (auto *Spec : CTD->specializations()) {
+
+        const TypeDecl *TD = static_cast<const TypeDecl *>(Spec);
+        if (S.Context.hasSameType(S.Context.getTypeDeclType(TD),
+                                  TSI->getType())) {
+
+          {
+            for (auto *R : Spec->redecls()) {
+              if (!R->hasAttr<PreferredNameAttr>())
+                R->addAttr(PNA->clone(S.Context));
+            }
+          }
+        }
+        return;
       }
-      return;
-    }
   }
 
   S.Diag(AL.getLoc(), diag::err_attribute_not_typedef_for_specialization)

``````````

</details>


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


More information about the cfe-commits mailing list