[{"id":3676023,"web_url":"http://patchwork.ozlabs.org/comment/3676023/","msgid":"<ca12a8d8-0303-4ad0-94f6-9c026cb7c8c2@redhat.com>","list_archive_url":null,"date":"2026-04-10T19:05:18","subject":"Re: [PATCH] c++/reflection: fn call with splice in decltype rejected\n [PR124835]","submitter":{"id":4337,"url":"http://patchwork.ozlabs.org/api/people/4337/","name":"Jason Merrill","email":"jason@redhat.com"},"content":"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\nWhat about a splice-expression with leading 'template'?  I think we can \njust drop this check and rely on _skip_entire_.\n\nOptionally, I wonder about using tentative parsing like for member \naccess 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\nIt would be good to check whether decltype gives the right answer.\n\nJason","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=O8nKSUQj;\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=O8nKSUQj","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 4fsmVC1Jb6z1y2d\n\tfor <incoming@patchwork.ozlabs.org>; Sat, 11 Apr 2026 05:05:53 +1000 (AEST)","from vm01.sourceware.org (localhost [127.0.0.1])\n\tby sourceware.org (Postfix) with ESMTP id 2193C4BA2E3E\n\tfor <incoming@patchwork.ozlabs.org>; Fri, 10 Apr 2026 19:05:52 +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 5A9774BA2E05\n for <gcc-patches@gcc.gnu.org>; Fri, 10 Apr 2026 19:05:23 +0000 (GMT)","from mail-qt1-f199.google.com (mail-qt1-f199.google.com\n [209.85.160.199]) by relay.mimecast.com with ESMTP with STARTTLS\n (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id\n us-mta-456-VQDPtvsYPDuLW59HbnRqtA-1; Fri, 10 Apr 2026 15:05:21 -0400","by mail-qt1-f199.google.com with SMTP id\n d75a77b69052e-50d6bf346adso49433181cf.1\n for <gcc-patches@gcc.gnu.org>; Fri, 10 Apr 2026 12:05:21 -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 d75a77b69052e-50dd561a34asm29172391cf.26.2026.04.10.12.05.19\n (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128);\n Fri, 10 Apr 2026 12:05:19 -0700 (PDT)"],"DKIM-Filter":["OpenDKIM Filter v2.11.0 sourceware.org 2193C4BA2E3E","OpenDKIM Filter v2.11.0 sourceware.org 5A9774BA2E05"],"DMARC-Filter":"OpenDMARC Filter v1.4.2 sourceware.org 5A9774BA2E05","ARC-Filter":"OpenARC Filter v1.0.0 sourceware.org 5A9774BA2E05","ARC-Seal":"i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1775847923; cv=none;\n b=PAtSuCY2FqVxM3knjvSISyd0BO0oqLTBz98vzDfJ1oPGWx59dTzAdExObujq/murkRyKrWlCSkq8Qesa07hDwf3scnWCSyI16KKaI4S30KQt+xJ7Ah23URvL131y1e51r5mut1ZTmFnbnwqNx3SV/53eAZwiq3iwFZMyo+cjVc0=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=sourceware.org; s=key;\n t=1775847923; c=relaxed/simple;\n bh=X2wfZOeCnN1wK57KnKsupYHMZOsTJCn3E7vHOei1j9Q=;\n h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From;\n b=uNRqXj5V7BsQyTZkZ1A1RHM3PqF1WLU3DTD+D1AFjCt/ZkPy1vJOJqB9N+pypcUObsqqTIG57jcJcs4XT+iV0Pyu1qe0wAeQTUwiL8gwQCxMGrHPqLgRJyyesx+isSWHpHi0PSSvjTtjOfZYKzU6/zfaE1p7HTNaZmguP2eZZj8=","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=1775847923;\n h=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n to:to: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=6c+/inqpleu+Wytly2fNoYjDKlJHCEkAXCZd7BLlD7Y=;\n b=O8nKSUQjID2lcLhHf4bSPLcceQu2bMfhBtTsUsuK5ntR16eAuOIXZRGRkjcmcgIpLq3q2u\n mgoZPJhyv1lTcFPegJFM1Ggp6KlM+8oM0OU/0e0t6VqZgKXQkuNlnCZU2o5fxnjMuQ5LIB\n 9u3ufLyNzjehPGmUL6M8tS2d97Xs56I=","X-MC-Unique":"VQDPtvsYPDuLW59HbnRqtA-1","X-Mimecast-MFC-AGG-ID":"VQDPtvsYPDuLW59HbnRqtA_1775847921","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20251104; t=1775847921; x=1776452721;\n h=content-transfer-encoding:in-reply-to:from:content-language\n :references: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=6c+/inqpleu+Wytly2fNoYjDKlJHCEkAXCZd7BLlD7Y=;\n b=Vnqo5uXw4+D917vgyYnGbfujYBQ05tVQmsZfjetIS3pMyLnYfcKZWgrO7jkSFaDkt/\n T1XGkJJiZHtffKjE92lBRTXNn+ag8t8wvwPRSPc8jig5Isk0RTUJa1LVjv1K0e7q4gyR\n jFuXNpa5nyOwf9fiNusmGKVNDqSRpyCv8ttW8GgUOB96k/6heedepu8Ow0xsKCeokHxV\n 9iY2dOoP00pU2tfKRHlSDuXsijqgUHp3vYxsvejxSZF6S/kpW5zFQNd8LtSZ/nPZ6gNJ\n QzGdPQbkb8oGJWKbPZYq3ah7Clpw8sMlQkt2s0eZEybQwKC0+DMi/7DdrRLfjX4TNkyB\n 08AQ==","X-Forwarded-Encrypted":"i=1;\n AJvYcCWdhI9K3BZfevq9T90IzZdK+31/RUqlEbIOW4RWN9/JVGHwzuW8wQcrNnj4lyCbBv29QwRpbuVmPeyGWw==@gcc.gnu.org","X-Gm-Message-State":"AOJu0YxwBm1ZUaAFreDwC5T01uVTmJjCADOygAQ2OMjZP2rVZTi1XCAe\n wZ2qPxstSlWel6WUH1PIQVDDQT1hHzeG5/E5eOrcLZo14E3cWjAmcjah8Zx4jNmKUd5QfZPp3yx\n DUrJoS0NECYTDwKoYj+MIaecoPev9le2sRR4lqjAWv0e8Za/x+4qMILtdjzA=","X-Gm-Gg":"AeBDieuGkjkBvJfefN4MZIiARoToUUG5WF9K+Jm1SudvZlysgDWMu/vzKc/Ztj4Sjjo\n p1eRC4olKVKb3Umb8i1Y+48eyTjZLhfTRQFnJTpkizzxc4l+Yv/k/5sfzp7e4Ch6QUV8HV9GG90\n g5Car7C95UdUHRftDsbXXM/mQkXh5Sa1LfieIh9TXYKtvJrXiJBHfqz93L1x8AANEZB2tw8QJDF\n rbR63y+th6W/wVUakN5GEvCZcM0zfuEdzrok6taDeeIjrm72yP9mgkuhwJBrBY7HiyrZoRq6wC1\n G25RsJVNYc6e80s9PfUk1Z4TmWgwtTBIvcRofz2p5ahWgxxCwgEbwk8ORILXiMgQa8gl6Fi1ZQL\n UzTnYdpJ1fWARv/VXGji2d0d+KdwL4BEjO0oOFDJWbNQQYNiXKo60tweUd8fuZIV8r0AMXegZcF\n RvXwWbraSgk+nhpFyWYcqn3sZwNAunfdw=","X-Received":["by 2002:a05:622a:5a8b:b0:50d:a8f5:1bef with SMTP id\n d75a77b69052e-50dd5bbe53fmr71797591cf.46.1775847920760;\n Fri, 10 Apr 2026 12:05:20 -0700 (PDT)","by 2002:a05:622a:5a8b:b0:50d:a8f5:1bef with SMTP id\n d75a77b69052e-50dd5bbe53fmr71796801cf.46.1775847920214;\n Fri, 10 Apr 2026 12:05:20 -0700 (PDT)"],"Message-ID":"<ca12a8d8-0303-4ad0-94f6-9c026cb7c8c2@redhat.com>","Date":"Fri, 10 Apr 2026 15:05:18 -0400","MIME-Version":"1.0","User-Agent":"Mozilla Thunderbird","Subject":"Re: [PATCH] c++/reflection: fn call with splice in decltype rejected\n [PR124835]","To":"Marek Polacek <polacek@redhat.com>, GCC Patches <gcc-patches@gcc.gnu.org>","References":"<20260410002735.1424952-1-polacek@redhat.com>","From":"Jason Merrill <jason@redhat.com>","In-Reply-To":"<20260410002735.1424952-1-polacek@redhat.com>","X-Mimecast-Spam-Score":"0","X-Mimecast-MFC-PROC-ID":"1IWWOyy9LCrBQwzcb8vjU6_Kmv5rN89x58jeIgokqcw_1775847921","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"}}]