[gcc r17-2863] c++: early DMI parsing and {} [PR126481]

Jason Merrill via Gcc-cvs <[email protected]> Fri, 31 Jul 2026 21:55:37 +0000 (GMT)
Newsgroups gmane.comp.gcc.cvs
Message-ID <[email protected]>
https://gcc.gnu.org/g:2a128109493455c4812d2b370327640dd62d29c0

commit r17-2863-g2a128109493455c4812d2b370327640dd62d29c0
Author: Jason Merrill <[email protected]>
Date:   Fri Jul 31 13:45:48 2026 -0400

    c++: early DMI parsing and {} [PR126481]
    
    Here I thought that only name lookup and use of 'this' could change in a
    complete class context, but this testcase demonstrates that an init-list
    also needs deferred parsing.
    
            PR c++/126481
    
    gcc/cp/ChangeLog:
    
            * parser.cc (cp_parser_early_parsing_nsdmi): Also defer {}.
    
    gcc/testsuite/ChangeLog:
    
            * g++.dg/cpp0x/nsdmi-defer8.C: New test.

Diff:
---
 gcc/cp/parser.cc                          |  2 ++
 gcc/testsuite/g++.dg/cpp0x/nsdmi-defer8.C | 15 +++++++++++++++
 2 files changed, 17 insertions(+)

diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index a4cfcfa480ef..19918cfa9de2 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -37312,6 +37312,8 @@ cp_parser_early_parsing_nsdmi (cp_parser *parser, tree field)
   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-defer8.C b/gcc/testsuite/g++.dg/cpp0x/nsdmi-defer8.C
new file mode 100644
index 000000000000..4e91985de646
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/nsdmi-defer8.C
@@ -0,0 +1,15 @@
+// PR c++/126481
+// { dg-do compile { target c++11 } }
+
+struct QPluginMetaData
+{
+  static constexpr int CurrentMetaDataVersion = 1;
+
+  struct Header {
+    int version = CurrentMetaDataVersion;
+  };
+
+  struct MagicHeader {
+    Header header = {};
+  };
+};