templ = tsubst_splice_expr (templ, args, complain, in_decl);
if (templ == error_mark_node)
return error_mark_node;
+ if (!DECL_TYPE_TEMPLATE_P (templ)
+ && !DECL_TEMPLATE_TEMPLATE_PARM_P (templ))
+ {
+ if (complain & tf_error)
+ {
+ auto_diagnostic_group d;
+ error_at (cp_expr_loc_or_input_loc (TREE_OPERAND (t, 0)),
+ "expected a reflection of a type template");
+ inform_tree_category (templ);
+ }
+ return error_mark_node;
+ }
tree targs = TREE_OPERAND (t, 1);
if (targs)
targs = tsubst_template_args (targs, args, complain, in_decl);
--- /dev/null
+// PR c++/124493
+// { dg-do compile { target c++26 } }
+// { dg-additional-options "-freflection" }
+
+struct Y { };
+template<decltype(^^::) R>
+constexpr auto f (typename [:R:]<0> x) { return x; } // { dg-error "expected a reflection of a type template" }
+constexpr auto a = f<^^Y>(Y{}); // { dg-error "no matching function for call" }
--- /dev/null
+// PR c++/124493
+// { dg-do compile { target c++26 } }
+// { dg-additional-options "-freflection" }
+
+template<typename T> void Y(T); // { dg-message "but .Y. is a function template" }
+template<decltype(^^::) R>
+constexpr auto f () -> [:R:]<0> { return {}; } // { dg-error "expected a reflection of a type template" }
+constexpr auto a = f<^^Y>(); // { dg-error "no matching function" }