]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++/reflection: splicing null reflection
authorMarek Polacek <polacek@redhat.com>
Fri, 17 Apr 2026 14:06:42 +0000 (10:06 -0400)
committerMarek Polacek <polacek@redhat.com>
Fri, 17 Apr 2026 14:07:11 +0000 (10:07 -0400)
Here we are printing:

  note: but ''lang_type' not supported by dump_expr<expression error>' is a type

because we represent a null reflection with unknown_type_node.  Let's
detect splicing a null reflection.

gcc/cp/ChangeLog:

* reflect.cc (splice): Detect a null reflection.

gcc/testsuite/ChangeLog:

* g++.dg/reflect/null6.C: New test.

Reviewed-by: Jason Merrill <jason@redhat.com>
gcc/cp/reflect.cc
gcc/testsuite/g++.dg/reflect/null6.C [new file with mode: 0644]

index bcd43cf2ab6ed1e82b11557d3596f756fa6bab70..59f8354a3cf132b3fd328a9df718fb7414ca10d9 100644 (file)
@@ -8525,6 +8525,12 @@ splice (tree refl)
       return error_mark_node;
     }
 
+  if (compare_reflections (refl, get_null_reflection ()))
+    {
+      error_at (loc, "cannot splice a null reflection");
+      return error_mark_node;
+    }
+
   /* This isn't checked in check_splice_expr, because reflect_kind isn't
      available there and variable_of (parameters_of (...)[...]) can be
      spliced.  */
diff --git a/gcc/testsuite/g++.dg/reflect/null6.C b/gcc/testsuite/g++.dg/reflect/null6.C
new file mode 100644 (file)
index 0000000..8b91ef7
--- /dev/null
@@ -0,0 +1,8 @@
+// { dg-do compile { target c++26 } }
+// { dg-additional-options "-freflection" }
+
+using info = decltype(^^::);
+constexpr auto null = info{};
+constexpr auto q = [:null:];  // { dg-error "cannot splice a null reflection" }
+[:null:] t1;                 // { dg-error "cannot splice a null reflection|expected" }
+[:null:]<int> t2;            // { dg-error "cannot splice a null reflection|expected" }