[clang] [C23] Handle type compatibility of unnamed records (PR #141783)
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Wed May 28 09:32:46 PDT 2025
================
@@ -359,3 +359,35 @@ struct alignment { // c17-error {{redefinition of 'alignment'}} \
c23-error {{type 'struct alignment' has a member with an attribute which currently causes the types to be treated as though they are incompatible}}
int x;
};
+
+// Both structures need to have a tag in order to be compatible within the same
+// translation unit.
+struct {int i;} nontag;
+struct tag {int i;} tagged; // c17-note 2 {{previous definition is here}}
+
+_Static_assert(1 == _Generic(tagged, struct tag {int i;}:1, default:0)); // c17-error {{redefinition of 'tag'}} \
+ c17-error {{static assertion failed}}
+_Static_assert(0 == _Generic(tagged, struct {int i;}:1, default:0));
+_Static_assert(0 == _Generic(nontag, struct tag {int i;}:1, default:0)); // c17-error {{redefinition of 'tag'}}
+// That means these two structures are not actually compatible; see GH141724.
+_Static_assert(0 == _Generic(nontag, struct {int i;}:1, default:0));
+
+// Also test the behavior within a function (so the declaration context is not
+// at the translation unit level).
+void nontag_func_test(void) {
----------------
AaronBallman wrote:
I've added a few more tests for you, but yup, that's still zero.
https://github.com/llvm/llvm-project/pull/141783
More information about the cfe-commits
mailing list