[clang] [clang] Centralize common checks for type attributes (PR #227421)

via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 1 10:55:42 PDT 2026


================
@@ -1668,6 +1656,25 @@ static bool checkCommonAttributeFeatures(Sema &S, const Ty *Node,
   return false;
 }
 
+template <typename Ty>
+static bool checkCommonAttributeFeatures(Sema &S, const Ty *Node,
+                                         const ParsedAttr &A,
+                                         bool SkipArgCountCheck) {
+  // Run the checks shared with type attributes (language options, target, and
+  // argument count). This also bails on unknown and ignored attributes.
+  if (checkCommonAttributeFeatures(S, A, SkipArgCountCheck))
+    return true;
+  // Check whether the attribute appertains to the given subject.
+  if (!A.diagnoseAppertainsTo(S, Node))
+    return true;
+  // Check whether the attribute is mutually exclusive with other attributes
+  // that have already been applied to the declaration.
+  if (!A.diagnoseMutualExclusion(S, Node))
+    return true;
----------------
elizabethandrews wrote:

> The type is essentially mid-construction when we process attributes. I am not sure how that affects appertainment checks. For example, does SubjectList<[Pointer]> mean the chunk that the attribute is applied to is a pointer, or the overall type being qualified is a pointer?

I might be overthinking this. I just remembered we have individual checks inside handlers for appertainment for some handlers now.   So we can probably just use whatever `Type` (or `QualType` ?) is at the site.   

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


More information about the cfe-commits mailing list