Tested x86_64-pc-linux-gnu, applying to trunk.
-- 8< --
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 | 2 ++
gcc/testsuite/g++.dg/cpp2a/typedef2.C | 5 +++++
2 files changed, 7 insertions(+)
create mode 100644 gcc/testsuite/g++.dg/cpp2a/typedef2.C
diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
index 79247302608..a2233107317 100644
--- a/gcc/cp/decl.cc
+++ b/gcc/cp/decl.cc
@@ -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
index 00000000000..e4a8195ce18
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/typedef2.C
@@ -0,0 +1,5 @@
+// PR c++/126031
+
+typedef struct {
+ struct S;
+} s;
base-commit: 17649698d6f1d1c626dcf245edd8e45f3f55a5eb
--
2.54.0