[gcc r17-2912] c++: early DMI and constructor default arg [PR126606]
Jason Merrill via Gcc-cvs <[email protected]> Mon, 3 Aug 2026 21:56:21 +0000 (GMT)
| Newsgroups | gmane.comp.gcc.cvs |
|---|---|
| Message-ID | <[email protected]> |
https://gcc.gnu.org/g:4569067c6f5206e97a319ec6bfa4e3446b3a41d1 commit r17-2912-g4569067c6f5206e97a319ec6bfa4e3446b3a41d1 Author: Jason Merrill <[email protected]> Date: Sat Aug 1 00:17:45 2026 -0400 c++: early DMI and constructor default arg [PR126606] 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. Diff: --- gcc/cp/parser.cc | 6 ++++-- gcc/testsuite/g++.dg/cpp0x/nsdmi-defer9.C | 10 ++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc index 67a1696f0262..85c5030acbb4 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 000000000000..74307188ff01 --- /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; +};