https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122465

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P3                          |P4

--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Untested fix:
2025-11-18  Jakub Jelinek  <[email protected]>

        PR c++/122465
        * parser.cc (cp_hide_range_decl): Return early for NULL range_decl.

        * g++.dg/cpp0x/pr122465.C: New test.

--- gcc/cp/parser.cc.jj 2025-11-17 15:23:03.940470500 +0100
+++ gcc/cp/parser.cc    2025-11-18 18:07:50.731806016 +0100
@@ -14911,7 +14911,7 @@ cp_hide_range_decl (tree *range_decl_p,
 {
   tree range_decl = *range_decl_p;
   cp_decomp *decomp = NULL;
-  if (range_decl == error_mark_node)
+  if (range_decl == error_mark_node || range_decl == NULL_TREE)
     return decomp;

   if (DECL_HAS_VALUE_EXPR_P (range_decl))
--- gcc/testsuite/g++.dg/cpp0x/pr122465.C.jj    2025-11-18 18:11:39.266570327
+0100
+++ gcc/testsuite/g++.dg/cpp0x/pr122465.C       2025-11-18 18:11:23.629791644
+0100
@@ -0,0 +1,11 @@
+// PR c++/122465
+// { dg-do compile { target c++11 } }
+
+void
+foo ()
+{    
+  int x = 0;
+  for (const T i = { i } : x)  // { dg-error "'T' does not name a type" }
+    ;                          // { dg-error "'begin' was not declared in this
scope" "" { target *-*-* } .-1 }
+}                              // { dg-error "'end' was not declared in this
scope" "" { target *-*-* } .-2 }
+                               // { dg-error "assignment \\\(not
initialization\\\) in declaration" "" { target *-*-* } .-3 }

Reply via email to