https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123998
--- Comment #1 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The trunk branch has been updated by Marek Polacek <[email protected]>: https://gcc.gnu.org/g:c684613dea0b00d222ebbae8439ea8fd8c1f1865 commit r16-8551-gc684613dea0b00d222ebbae8439ea8fd8c1f1865 Author: Marek Polacek <[email protected]> Date: Fri Mar 20 12:34:31 2026 -0400 c++/reflection: reject invalid template splice [PR123998] When we have "template [:R:]" without template arguments, the splice has to designate a function template. E.g., void foo (int); template [: ^^foo :] (0); // invalid We check this in cp_parser_splice_expression. But when the splice is dependent, we don't check it when instantiating, thus missing the error in template [: N == 0 ? ^^foo : ^^:: :] (0); This patch introduces SPLICE_EXPR_TEMPLATE_P and SPLICE_EXPR_TARGS_P, and moves the checking into check_splice_expr. It also adds a missing check for DECL_TYPE_TEMPLATE_P in case we have a splice-expression of the form template splice-specialization-specifier. PR c++/123998 gcc/cp/ChangeLog: * cp-tree.h (SPLICE_EXPR_TEMPLATE_P): Define. (SET_SPLICE_EXPR_TEMPLATE_P): Define. (SPLICE_EXPR_TARGS_P): Define. (SET_SPLICE_EXPR_TARGS_P): Define. (check_splice_expr): Adjust. * parser.cc (cp_parser_splice_expression): Do SET_SPLICE_EXPR_TEMPLATE_P and SET_SPLICE_EXPR_TARGS_P. Adjust the call to check_splice_expr. Move the template_p checking into check_splice_expr. * pt.cc (tsubst_splice_expr): Do SET_SPLICE_EXPR_TEMPLATE_P and SET_SPLICE_EXPR_TARGS_P. Adjust the call to check_splice_expr. * reflect.cc (eval_constant_of): Adjust the call to check_splice_expr. (check_splice_expr): Two new bool parameters. Add the template_p checking from cp_parser_splice_expression. Allow variable_template_p in the assert. Add a check for DECL_TYPE_TEMPLATE_P. gcc/testsuite/ChangeLog: * g++.dg/reflect/crash11.C: Adjust dg-error. * g++.dg/reflect/splice5.C: Likewise. Reviewed-by: Jason Merrill <[email protected]>
