================
@@ -207,10 +217,17 @@ bool Sema::CheckCountedByAttrOnField(FieldDecl *FD, Expr 
*E, bool CountInBytes,
     return true;
   }
 
+  // Reject if both FD and CountFD are in the same union - they share storage.
+  if (FD->getParent() == CountFD->getParent() && FD->getParent()->isUnion()) {
+    Diag(FD->getBeginLoc(), diag::err_count_attr_in_union)
+        << Kind << FD->getSourceRange();
+    return true;
+  }
+
   if (FD->getParent() != CountFD->getParent()) {
     if (CountFD->getParent()->isUnion()) {
-      Diag(CountFD->getBeginLoc(), diag::err_count_attr_refer_to_union)
-          << Kind << CountFD->getSourceRange();
+      Diag(FD->getBeginLoc(), diag::err_count_attr_refer_to_union)
+          << Kind << FD->getSourceRange();
----------------
bwendling wrote:

This change didn't cause any test failures? :grimacing: 

https://github.com/llvm/llvm-project/pull/171996
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to