]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: naming typedef and incomplete class [PR126031]
authorJason Merrill <jason@redhat.com>
Wed, 1 Jul 2026 15:49:39 +0000 (11:49 -0400)
committerJason Merrill <jason@redhat.com>
Mon, 6 Jul 2026 15:04:06 +0000 (11:04 -0400)
We can't look at the bases and members of a forward-declared nested class,
and such a forward declaration can't contain problematic constructs, so
treat it as OK.

PR c++/126031
PR c++/121552

gcc/cp/ChangeLog:

* decl.cc (maybe_diagnose_non_c_class_typedef_for_linkage): Handle
incomplete type.

gcc/testsuite/ChangeLog:

* g++.dg/cpp2a/typedef2.C: New test.

gcc/cp/decl.cc
gcc/testsuite/g++.dg/cpp2a/typedef2.C [new file with mode: 0644]

index 79247302608d373ebd1cf7ef4d414d0cd0470b51..a22331073173b7f41233e940e14b21188fce6583 100644 (file)
@@ -13775,6 +13775,8 @@ diagnose_non_c_class_typedef_for_linkage (tree type, tree orig)
 static bool
 maybe_diagnose_non_c_class_typedef_for_linkage (tree type, tree orig, tree t)
 {
+  if (!COMPLETE_TYPE_P (t))
+    return false;
   if (!BINFO_BASE_BINFOS (TYPE_BINFO (t))->is_empty ())
     {
       auto_diagnostic_group d;
diff --git a/gcc/testsuite/g++.dg/cpp2a/typedef2.C b/gcc/testsuite/g++.dg/cpp2a/typedef2.C
new file mode 100644 (file)
index 0000000..e4a8195
--- /dev/null
@@ -0,0 +1,5 @@
+// PR c++/126031
+
+typedef struct {
+  struct S;
+} s;