[{"id":3676934,"web_url":"http://patchwork.ozlabs.org/comment/3676934/","msgid":"<b2995f1d-af6c-4d51-81ab-a93fe33cbee7@redhat.com>","list_archive_url":null,"date":"2026-04-13T21:24:25","subject":"Re: [PATCH v2] c++/reflection: fn call with splice in decltype\n rejected [PR124835]","submitter":{"id":4337,"url":"http://patchwork.ozlabs.org/api/people/4337/","name":"Jason Merrill","email":"jason@redhat.com"},"content":"On 4/13/26 2:23 PM, Marek Polacek wrote:\n> On Fri, Apr 10, 2026 at 03:05:18PM -0400, Jason Merrill wrote:\n>> On 4/9/26 8:27 PM, Marek Polacek wrote:\n>>> I found this while working on the mangling patch and this bug\n>>> blocks that patch.\n>>>\n>>> Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?\n>>>\n>>> -- >8 --\n>>> Here we reject the valid\n>>>\n>>>     decltype([:^^foo<int>:](42))\n>>>\n>>> saying that a ')' is expected.  [dcl.type.decltype] says \"if E is an\n>>> unparenthesized splice-expression, decltype(E) is...\" and we handle it\n>>> by calling _splice_expression and setting id_expression_or_member_access_p.\n>>>\n>>> But for the code above we shouldn't do this, because the [: :] isn't\n>>> the sole operand of decltype.  _nth_token_starts_splice_without_nns_p\n>>> checks that there's no :: after the :] but here we want to check that\n>>> the [: :] is followed by a ')'.\n>>>\n>>> \tPR c++/124835\n>>>\n>>> gcc/cp/ChangeLog:\n>>>\n>>> \t* parser.cc (cp_parser_decltype_expr): Check that [: :] is\n>>> \tfollowed by a ')' before declaring it an unparenthesized\n>>> \tsplice-expression.\n>>>\n>>> gcc/testsuite/ChangeLog:\n>>>\n>>> \t* g++.dg/reflect/decltype2.C: New test.\n>>> ---\n>>>    gcc/cp/parser.cc                         | 11 ++++++++++-\n>>>    gcc/testsuite/g++.dg/reflect/decltype2.C | 12 ++++++++++++\n>>>    2 files changed, 22 insertions(+), 1 deletion(-)\n>>>    create mode 100644 gcc/testsuite/g++.dg/reflect/decltype2.C\n>>>\n>>> diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc\n>>> index fe27a15a283..6493a26a149 100644\n>>> --- a/gcc/cp/parser.cc\n>>> +++ b/gcc/cp/parser.cc\n>>> @@ -19387,7 +19387,16 @@ cp_parser_decltype_expr (cp_parser *parser,\n>>>          /* [dcl.type.decltype] \"if E is an unparenthesized splice-expression,\n>>>    \t decltype(E) is the type of the entity, object, or value designated\n>>>    \t by the splice-specifier of E\"  */\n>>> -      if (cp_parser_nth_token_starts_splice_without_nns_p (parser, 1))\n>>> +      const bool unparenthesized_splice_expr_p = [&] {\n>>> +\t/* The next token must be '[:'.  */\n>>> +\tif (cp_lexer_next_token_is_not (parser->lexer, CPP_OPEN_SPLICE))\n>>> +\t  return false;\n>>\n>> What about a splice-expression with leading 'template'?  I think we can just\n>> drop this check and rely on _skip_entire_.\n> \n> I think we can't have a valid leading 'template' here: in \"template [:X:]\"\n> the X must designate a function template, and\n> \n>    decltype(template [:^^foo:])\n> \n> results in \"cannot resolve address of overloaded function\".  But let's\n> drop the first check anyway.\n>   \n>> Optionally, I wonder about using tentative parsing like for member access\n>> just above, rather than token scanning and then parsing.\n>>\n>>> +\t/* Skip to the end of the ':]' and see if the closing ')' follows.  */\n>>> +\tsaved_token_sentinel toks (parser->lexer, STS_ROLLBACK);\n>>> +\treturn (cp_parser_skip_entire_splice_expr (parser)\n>>> +\t\t&& cp_lexer_next_token_is (parser->lexer, CPP_CLOSE_PAREN));\n>>> +      } ();\n>>> +      if (unparenthesized_splice_expr_p)\n>>>    \t{\n>>>    \t  cp_id_kind idk;\n>>>    \t  expr = cp_parser_splice_expression (parser, /*template_p=*/false,\n>>> diff --git a/gcc/testsuite/g++.dg/reflect/decltype2.C b/gcc/testsuite/g++.dg/reflect/decltype2.C\n>>> new file mode 100644\n>>> index 00000000000..cc5532c7957\n>>> --- /dev/null\n>>> +++ b/gcc/testsuite/g++.dg/reflect/decltype2.C\n>>> @@ -0,0 +1,12 @@\n>>> +// PR c++/124835\n>>> +// { dg-do compile { target c++26 } }\n>>> +// { dg-additional-options \"-freflection\" }\n>>> +\n>>> +template<typename T>\n>>> +constexpr T foo (T t) { return t; }\n>>> +\n>>> +int bar (int);\n>>> +\n>>> +static_assert ([:^^foo<int>:](42) == 42);\n>>> +decltype([:^^foo<int>:](42)) a = 42;\n>>> +decltype([:^^foo<int>:]) &b = bar;\n>>\n>> It would be good to check whether decltype gives the right answer.\n> \n> Yes, done.  Also let's check decltype((...)).\n> \n> Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?\n\nOK.\n\n> -- >8 --\n> Here we reject the valid\n> \n>    decltype([:^^foo<int>:](42))\n> \n> saying that a ')' is expected.  [dcl.type.decltype] says \"if E is an\n> unparenthesized splice-expression, decltype(E) is...\" and we handle it\n> by calling _splice_expression and setting id_expression_or_member_access_p.\n> \n> But for the code above we shouldn't do this, because the [: :] isn't\n> the sole operand of decltype.  _nth_token_starts_splice_without_nns_p\n> checks that there's no :: after the :] but here we want to check that\n> the [: :] is followed by a ')'.\n> \n> \tPR c++/124835\n> \n> gcc/cp/ChangeLog:\n> \n> \t* parser.cc (cp_parser_decltype_expr): Check that [: :] is\n> \tfollowed by a ')' before declaring it an unparenthesized\n> \tsplice-expression.\n> \n> gcc/testsuite/ChangeLog:\n> \n> \t* g++.dg/reflect/decltype2.C: New test.\n> ---\n>   gcc/cp/parser.cc                         | 13 ++++++++++--\n>   gcc/testsuite/g++.dg/reflect/decltype2.C | 25 ++++++++++++++++++++++++\n>   2 files changed, 36 insertions(+), 2 deletions(-)\n>   create mode 100644 gcc/testsuite/g++.dg/reflect/decltype2.C\n> \n> diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc\n> index fe27a15a283..9dbc2933e7b 100644\n> --- a/gcc/cp/parser.cc\n> +++ b/gcc/cp/parser.cc\n> @@ -19387,10 +19387,19 @@ cp_parser_decltype_expr (cp_parser *parser,\n>         /* [dcl.type.decltype] \"if E is an unparenthesized splice-expression,\n>   \t decltype(E) is the type of the entity, object, or value designated\n>   \t by the splice-specifier of E\"  */\n> -      if (cp_parser_nth_token_starts_splice_without_nns_p (parser, 1))\n> +      const bool unparenthesized_splice_expr_p = [&] {\n> +\tif (!flag_reflection)\n> +\t  return false;\n> +\t/* Skip to the end of the ':]' and see if the closing ')' follows.  */\n> +\tsaved_token_sentinel toks (parser->lexer, STS_ROLLBACK);\n> +\treturn (cp_parser_skip_entire_splice_expr (parser)\n> +\t\t&& cp_lexer_next_token_is (parser->lexer, CPP_CLOSE_PAREN));\n> +      } ();\n> +      if (unparenthesized_splice_expr_p)\n>   \t{\n>   \t  cp_id_kind idk;\n> -\t  expr = cp_parser_splice_expression (parser, /*template_p=*/false,\n> +\t  const bool template_p = cp_parser_optional_template_keyword (parser);\n> +\t  expr = cp_parser_splice_expression (parser, template_p,\n>   \t\t\t\t\t      /*address_p=*/false,\n>   \t\t\t\t\t      /*template_arg_p=*/false,\n>   \t\t\t\t\t      /*member_access_p=*/false, &idk);\n> diff --git a/gcc/testsuite/g++.dg/reflect/decltype2.C b/gcc/testsuite/g++.dg/reflect/decltype2.C\n> new file mode 100644\n> index 00000000000..075d490d368\n> --- /dev/null\n> +++ b/gcc/testsuite/g++.dg/reflect/decltype2.C\n> @@ -0,0 +1,25 @@\n> +// PR c++/124835\n> +// { dg-do compile { target c++26 } }\n> +// { dg-additional-options \"-freflection\" }\n> +\n> +template <typename T, typename U>\n> +constexpr bool is_same_v = false;\n> +\n> +template <typename T>\n> +constexpr bool is_same_v<T, T> = true;\n> +\n> +template<typename T>\n> +constexpr T foo (T t) { return t; }\n> +\n> +template<typename T>\n> +struct S { };\n> +\n> +static_assert([:^^foo<int>:](42) == 42);\n> +static_assert(is_same_v<decltype([:^^foo<int>:]), int(int)>);\n> +static_assert(is_same_v<decltype([:^^foo<int>:](42)), int>);\n> +static_assert(is_same_v<decltype(template [:^^foo:](0)), int>);\n> +static_assert(is_same_v<decltype(template [:^^foo:]<int>(0)), int>);\n> +static_assert(is_same_v<decltype(([:^^foo<int>:])), int(&)(int)>);\n> +static_assert(is_same_v<decltype(([:^^foo<int>:](42))), int>);\n> +static_assert(is_same_v<decltype((template [:^^foo:](0))), int>);\n> +static_assert(is_same_v<decltype((template [:^^foo:]<int>(0))), int>);\n> \n> base-commit: 9c694b3ecd0eb5308e85a0eac69c4b2d008ca83e","headers":{"Return-Path":"<gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org>","X-Original-To":["incoming@patchwork.ozlabs.org","gcc-patches@gcc.gnu.org"],"Delivered-To":["patchwork-incoming@legolas.ozlabs.org","gcc-patches@gcc.gnu.org"],"Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (1024-bit key;\n unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256\n header.s=mimecast20190719 header.b=hmrwDiMH;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org\n (client-ip=2620:52:6:3111::32; helo=vm01.sourceware.org;\n envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org;\n receiver=patchwork.ozlabs.org)","sourceware.org;\n\tdkim=pass (1024-bit key,\n unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256\n header.s=mimecast20190719 header.b=hmrwDiMH","sourceware.org; dmarc=pass (p=quarantine dis=none)\n header.from=redhat.com","sourceware.org; spf=pass smtp.mailfrom=redhat.com","server2.sourceware.org;\n arc=none smtp.remote-ip=170.10.133.124"],"Received":["from vm01.sourceware.org (vm01.sourceware.org\n [IPv6:2620:52:6:3111::32])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4fvgRJ5NF7z1y2d\n\tfor <incoming@patchwork.ozlabs.org>; Tue, 14 Apr 2026 07:25:00 +1000 (AEST)","from vm01.sourceware.org (localhost [127.0.0.1])\n\tby sourceware.org (Postfix) with ESMTP id E7DD94BA2E08\n\tfor <incoming@patchwork.ozlabs.org>; Mon, 13 Apr 2026 21:24:58 +0000 (GMT)","from us-smtp-delivery-124.mimecast.com\n (us-smtp-delivery-124.mimecast.com [170.10.133.124])\n by sourceware.org (Postfix) with ESMTP id D69984BA2E04\n for <gcc-patches@gcc.gnu.org>; Mon, 13 Apr 2026 21:24:29 +0000 (GMT)","from mail-qt1-f197.google.com (mail-qt1-f197.google.com\n [209.85.160.197]) by relay.mimecast.com with ESMTP with STARTTLS\n (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id\n us-mta-544-Gvm8_5ffNeCaEmThNdfNQw-1; Mon, 13 Apr 2026 17:24:27 -0400","by mail-qt1-f197.google.com with SMTP id\n d75a77b69052e-50b4076dc16so115109471cf.2\n for <gcc-patches@gcc.gnu.org>; Mon, 13 Apr 2026 14:24:27 -0700 (PDT)","from [192.168.50.130]\n (130-44-146-247.s12789.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com.\n [130.44.146.247]) by smtp.gmail.com with ESMTPSA id\n af79cd13be357-8ddb9738cd3sm969931485a.40.2026.04.13.14.24.25\n (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128);\n Mon, 13 Apr 2026 14:24:25 -0700 (PDT)"],"DKIM-Filter":["OpenDKIM Filter v2.11.0 sourceware.org E7DD94BA2E08","OpenDKIM Filter v2.11.0 sourceware.org D69984BA2E04"],"DMARC-Filter":"OpenDMARC Filter v1.4.2 sourceware.org D69984BA2E04","ARC-Filter":"OpenARC Filter v1.0.0 sourceware.org D69984BA2E04","ARC-Seal":"i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1776115469; cv=none;\n b=cOb8MA7GXrzi2Fx7PQJAijd1XK9sDkCWyxBzbNi7IF4ck6Sn3LEbyxGP1hT6Mj+P7jwHbysrgLH5rYvQOhnGF2HNKrT+csV09bqf2KndjiFbdDs8oIkDgqX0eGyYnSlj4ypzcIsoeTDJKWLhtnzNfUt+42IgEcEOHjjEPZLzSD0=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=sourceware.org; s=key;\n t=1776115469; c=relaxed/simple;\n bh=6ypApwDN/tpqy4rBP3iFUDGf51Ymuq/BJCjZEh94HHw=;\n h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From;\n b=KEussFZF5/WXicrhPw4R4UvUo5LkkYPekGduiq27alPmN9JlpIQaGUfxHkZH55AWQxWCznMUDc8rpCXN1stS2ZHYN1Cj7KrREKzX0OzpRaCcN/eJM/BrpnpYMTuaC8TBbdRJN0re62uJtSV//VoV73YY/rFj9ohWk7UTmoCPQQM=","ARC-Authentication-Results":"i=1; server2.sourceware.org","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n s=mimecast20190719; t=1776115469;\n h=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n to:to:cc:cc:mime-version:mime-version:content-type:content-type:\n content-transfer-encoding:content-transfer-encoding:\n in-reply-to:in-reply-to:references:references;\n bh=kexfFgjKxMsBxwZlXG/01eKuik/dLrmy71iPQ0amYNs=;\n b=hmrwDiMHjm1RWsePHhHWIlyBWPfB7aaTB8N218x8t2h9PZ33EMXOxHRUA4wDMTGuCucS1Z\n Z9wwy9NlaUB66rMD6AnXT0+rJRXJBx2lRGLnxtrQw88BWShowWEx1ps+3RMgkjzZzUWiMq\n M/1MAIzwrK2wAmjCTrPQq4s83jqQky0=","X-MC-Unique":"Gvm8_5ffNeCaEmThNdfNQw-1","X-Mimecast-MFC-AGG-ID":"Gvm8_5ffNeCaEmThNdfNQw_1776115467","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20251104; t=1776115467; x=1776720267;\n h=content-transfer-encoding:in-reply-to:from:content-language\n :references:cc:to:subject:user-agent:mime-version:date:message-id\n :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id\n :reply-to;\n bh=kexfFgjKxMsBxwZlXG/01eK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K1SNl86mGhg7g==","X-Received":["by 2002:a05:620a:1990:b0:8d9:4e4a:94ff with SMTP id\n af79cd13be357-8ddcecbc859mr2205746085a.37.1776115467049;\n Mon, 13 Apr 2026 14:24:27 -0700 (PDT)","by 2002:a05:620a:1990:b0:8d9:4e4a:94ff with SMTP id\n af79cd13be357-8ddcecbc859mr2205742585a.37.1776115466457;\n Mon, 13 Apr 2026 14:24:26 -0700 (PDT)"],"Message-ID":"<b2995f1d-af6c-4d51-81ab-a93fe33cbee7@redhat.com>","Date":"Mon, 13 Apr 2026 17:24:25 -0400","MIME-Version":"1.0","User-Agent":"Mozilla Thunderbird","Subject":"Re: [PATCH v2] c++/reflection: fn call with splice in decltype\n rejected [PR124835]","To":"Marek Polacek <polacek@redhat.com>","Cc":"GCC Patches <gcc-patches@gcc.gnu.org>","References":"<20260410002735.1424952-1-polacek@redhat.com>\n <ca12a8d8-0303-4ad0-94f6-9c026cb7c8c2@redhat.com>\n <ad00nW_wFL_TxjW6@redhat.com>","From":"Jason Merrill <jason@redhat.com>","In-Reply-To":"<ad00nW_wFL_TxjW6@redhat.com>","X-Mimecast-Spam-Score":"0","X-Mimecast-MFC-PROC-ID":"mkjFgJG-OURp0Dq9uBX5qvODmKLdZgJ90GKq3RikiJ8_1776115467","X-Mimecast-Originator":"redhat.com","Content-Language":"en-US","Content-Type":"text/plain; charset=UTF-8; format=flowed","Content-Transfer-Encoding":"7bit","X-BeenThere":"gcc-patches@gcc.gnu.org","X-Mailman-Version":"2.1.30","Precedence":"list","List-Id":"Gcc-patches mailing list <gcc-patches.gcc.gnu.org>","List-Unsubscribe":"<https://gcc.gnu.org/mailman/options/gcc-patches>,\n <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe>","List-Archive":"<https://gcc.gnu.org/pipermail/gcc-patches/>","List-Post":"<mailto:gcc-patches@gcc.gnu.org>","List-Help":"<mailto:gcc-patches-request@gcc.gnu.org?subject=help>","List-Subscribe":"<https://gcc.gnu.org/mailman/listinfo/gcc-patches>,\n <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe>","Errors-To":"gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org"}}]