[pushed] c++: early DMI and constructor default arg [PR126606]
Jason Merrill <[email protected]> Mon, 3 Aug 2026 17:55:20 -0400
| Newsgroups | gmane.comp.gcc.patches |
|---|---|
| Message-ID | <[email protected]> |
Tested x86_64-pc-linux-gnu, applying to trunk.
-- 8< --
This testcase demonstrates that the issue in 126481 was not the {} but
the member of class type.
PR c++/126606
PR c++/126481
gcc/cp/ChangeLog:
* parser.cc (cp_parser_early_parsing_nsdmi): Check
MAYBE_CLASS_TYPE_P instead of {}.
gcc/testsuite/ChangeLog:
* g++.dg/cpp0x/nsdmi-defer9.C: New test.
---
gcc/cp/parser.cc | 6 ++++--
gcc/testsuite/g++.dg/cpp0x/nsdmi-defer9.C | 10 ++++++++++
2 files changed, 14 insertions(+), 2 deletions(-)
create mode 100644 gcc/testsuite/g++.dg/cpp0x/nsdmi-defer9.C
diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index 67a1696f026..85c5030acbb 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -37309,11 +37309,13 @@ cp_parser_early_parsing_nsdmi (cp_parser *parser, tree field)
if (TREE_CODE (init) != DEFERRED_PARSE)
return true;
+ /* Initializing a class might need other deferred parses. */
+ if (MAYBE_CLASS_TYPE_P (strip_array_types (TREE_TYPE (field))))
+ return false;
+
cp_token_cache *tokens = DEFPARSE_TOKENS (init);
for (cp_token *p = tokens->first; p != tokens->last; ++p)
if (p->type == CPP_NAME
- /* = {} might depend on other DMI that haven't been parsed. */
- || p->type == CPP_OPEN_BRACE
|| p->keyword == RID_THIS
|| p->keyword == RID_OPERATOR)
/* There's a name to look up or 'this', give up. */
diff --git a/gcc/testsuite/g++.dg/cpp0x/nsdmi-defer9.C b/gcc/testsuite/g++.dg/cpp0x/nsdmi-defer9.C
new file mode 100644
index 00000000000..74307188ff0
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/nsdmi-defer9.C
@@ -0,0 +1,10 @@
+// PR c++/126606
+// { dg-do compile { target c++11 } }
+
+struct s1 {
+ struct s2
+ {
+ s2(int a = 0, int b = 1){}
+ };
+ s2 a = 1;
+};
base-commit: 8fb57eda04f88f4e0d1cbbcc209533fd9689dd9d
--
2.55.0