/* [dcl.type.decltype] "if E is an unparenthesized splice-expression,
decltype(E) is the type of the entity, object, or value designated
by the splice-specifier of E" */
- if (cp_parser_nth_token_starts_splice_without_nns_p (parser, 1))
+ const bool unparenthesized_splice_expr_p = [&] {
+ if (!flag_reflection)
+ return false;
+ /* Skip to the end of the ':]' and see if the closing ')' follows. */
+ saved_token_sentinel toks (parser->lexer, STS_ROLLBACK);
+ return (cp_parser_skip_entire_splice_expr (parser)
+ && cp_lexer_next_token_is (parser->lexer, CPP_CLOSE_PAREN));
+ } ();
+ if (unparenthesized_splice_expr_p)
{
cp_id_kind idk;
- expr = cp_parser_splice_expression (parser, /*template_p=*/false,
+ const bool template_p = cp_parser_optional_template_keyword (parser);
+ expr = cp_parser_splice_expression (parser, template_p,
/*address_p=*/false,
/*template_arg_p=*/false,
/*member_access_p=*/false, &idk);
--- /dev/null
+// PR c++/124835
+// { dg-do compile { target c++26 } }
+// { dg-additional-options "-freflection" }
+
+template <typename T, typename U>
+constexpr bool is_same_v = false;
+
+template <typename T>
+constexpr bool is_same_v<T, T> = true;
+
+template<typename T>
+constexpr T foo (T t) { return t; }
+
+template<typename T>
+struct S { };
+
+static_assert([:^^foo<int>:](42) == 42);
+static_assert(is_same_v<decltype([:^^foo<int>:]), int(int)>);
+static_assert(is_same_v<decltype([:^^foo<int>:](42)), int>);
+static_assert(is_same_v<decltype(template [:^^foo:](0)), int>);
+static_assert(is_same_v<decltype(template [:^^foo:]<int>(0)), int>);
+static_assert(is_same_v<decltype(([:^^foo<int>:])), int(&)(int)>);
+static_assert(is_same_v<decltype(([:^^foo<int>:](42))), int>);
+static_assert(is_same_v<decltype((template [:^^foo:](0))), int>);
+static_assert(is_same_v<decltype((template [:^^foo:]<int>(0))), int>);