[{"id":3678368,"web_url":"http://patchwork.ozlabs.org/comment/3678368/","msgid":"<f451dea9-8d46-4ff3-8ab9-a055605b56b4@redhat.com>","list_archive_url":null,"date":"2026-04-16T20:28:39","subject":"Re: [PATCH v2] c++/reflection: splicing null reflection","submitter":{"id":4337,"url":"http://patchwork.ozlabs.org/api/people/4337/","name":"Jason Merrill","email":"jason@redhat.com"},"content":"On 4/16/26 4:25 PM, Marek Polacek wrote:\n> On Thu, Apr 16, 2026 at 01:29:29PM -0400, Jason Merrill wrote:\n>> On 4/16/26 11:38 AM, Marek Polacek wrote:\n>>> On Thu, Apr 16, 2026 at 09:40:47AM -0400, Jason Merrill wrote:\n>>>> On 4/15/26 7:52 PM, Marek Polacek wrote:\n>>>>> Tested reflect/* on x86_64-pc-linux-gnu, ok for trunk?\n>>>>>\n>>>>> -- >8 --\n>>>>> Here we are printing:\n>>>>>\n>>>>>      note: but ''lang_type' not supported by dump_expr<expression error>' is a type\n>>>>>\n>>>>> because we represent a null reflection with unknown_type_node.  Let's\n>>>>> not print anything in that case; unknown_type_node can also be\n>>>>> <unresolved overloaded function type>.\n>>>>\n>>>> Can we diagnose sooner trying to splice a null reflection?  That should be\n>>>> ill-formed regardless of whether we expect it to be a type or expression or\n>>>> whatever.\n>>>\n>>> Sounds good, thanks.\n>>>\n>>> Tested reflect/* on x86_64-pc-linux-gnu, ok for trunk?\n>>>\n>>> -- >8 --\n>>> Here we are printing:\n>>>\n>>>     note: but ''lang_type' not supported by dump_expr<expression error>' is a type\n>>>\n>>> because we represent a null reflection with unknown_type_node.  Let's\n>>> detect splicing a null reflection.\n>>>\n>>> gcc/cp/ChangeLog:\n>>>\n>>> \t* reflect.cc (check_splice_expr): Detect a null reflection.\n>>>\n>>> gcc/testsuite/ChangeLog:\n>>>\n>>> \t* g++.dg/reflect/null6.C: New test.\n>>> ---\n>>>    gcc/cp/reflect.cc                    | 7 +++++++\n>>>    gcc/testsuite/g++.dg/reflect/null6.C | 6 ++++++\n>>>    2 files changed, 13 insertions(+)\n>>>    create mode 100644 gcc/testsuite/g++.dg/reflect/null6.C\n>>>\n>>> diff --git a/gcc/cp/reflect.cc b/gcc/cp/reflect.cc\n>>> index 2b7e7033953..ea7616a62bc 100644\n>>> --- a/gcc/cp/reflect.cc\n>>> +++ b/gcc/cp/reflect.cc\n>>> @@ -8929,6 +8929,13 @@ check_splice_expr (location_t loc, location_t start_loc, tree t,\n>>>    \t\t   bool address_p, bool member_access_p, bool template_p,\n>>>    \t\t   bool targs_p, bool complain_p)\n>>>    {\n>>> +  if (t == unknown_type_node)\n>>> +    {\n>>> +      if (complain_p)\n>>> +\terror_at (loc, \"cannot splice a null reflection\");\n>>> +      return false;\n>>> +    }\n>>> +\n>>>      /* We may not have gotten an expression.  */\n>>>      if (TREE_CODE (t) == TYPE_DECL\n>>>          || TREE_CODE (t) == NAMESPACE_DECL\n>>> diff --git a/gcc/testsuite/g++.dg/reflect/null6.C b/gcc/testsuite/g++.dg/reflect/null6.C\n>>> new file mode 100644\n>>> index 00000000000..bfa2b6ba241\n>>> --- /dev/null\n>>> +++ b/gcc/testsuite/g++.dg/reflect/null6.C\n>>> @@ -0,0 +1,6 @@\n>>> +// { dg-do compile { target c++26 } }\n>>> +// { dg-additional-options \"-freflection\" }\n>>> +\n>>> +using info = decltype(^^::);\n>>> +constexpr auto null = info{};\n>>> +constexpr auto q = [:null:];  // { dg-error \"cannot splice a null reflection\" }\n>>\n>> Please also test null in a splice-type-specifier, with and without template\n>> arguments.\n> \n> Done.  And actually let's check for a null reflection in splice.  This\n> is on top of Jakub's PR123783 patch.\n> \n> Tested reflect/* on x86_64-pc-linux-gnu, ok for trunk?\n\nOK.\n\n> -- >8 --\n> Here we are printing:\n> \n>    note: but ''lang_type' not supported by dump_expr<expression error>' is a type\n> \n> because we represent a null reflection with unknown_type_node.  Let's\n> detect splicing a null reflection.\n> \n> gcc/cp/ChangeLog:\n> \n> \t* reflect.cc (splice): Detect a null reflection.\n> \n> gcc/testsuite/ChangeLog:\n> \n> \t* g++.dg/reflect/null6.C: New test.\n> ---\n>   gcc/cp/reflect.cc                    | 6 ++++++\n>   gcc/testsuite/g++.dg/reflect/null6.C | 8 ++++++++\n>   2 files changed, 14 insertions(+)\n>   create mode 100644 gcc/testsuite/g++.dg/reflect/null6.C\n> \n> diff --git a/gcc/cp/reflect.cc b/gcc/cp/reflect.cc\n> index bcd43cf2ab6..59f8354a3cf 100644\n> --- a/gcc/cp/reflect.cc\n> +++ b/gcc/cp/reflect.cc\n> @@ -8525,6 +8525,12 @@ splice (tree refl)\n>         return error_mark_node;\n>       }\n>   \n> +  if (compare_reflections (refl, get_null_reflection ()))\n> +    {\n> +      error_at (loc, \"cannot splice a null reflection\");\n> +      return error_mark_node;\n> +    }\n> +\n>     /* This isn't checked in check_splice_expr, because reflect_kind isn't\n>        available there and variable_of (parameters_of (...)[...]) can be\n>        spliced.  */\n> diff --git a/gcc/testsuite/g++.dg/reflect/null6.C b/gcc/testsuite/g++.dg/reflect/null6.C\n> new file mode 100644\n> index 00000000000..8b91ef756eb\n> --- /dev/null\n> +++ b/gcc/testsuite/g++.dg/reflect/null6.C\n> @@ -0,0 +1,8 @@\n> +// { dg-do compile { target c++26 } }\n> +// { dg-additional-options \"-freflection\" }\n> +\n> +using info = decltype(^^::);\n> +constexpr auto null = info{};\n> +constexpr auto q = [:null:];  // { dg-error \"cannot splice a null reflection\" }\n> +[:null:] t1;\t\t      // { dg-error \"cannot splice a null reflection|expected\" }\n> +[:null:]<int> t2;\t      // { dg-error \"cannot splice a null reflection|expected\" }\n> \n> base-commit: 7c84b2a62827b3509b25727694c9f0eac9e96b80\n> prerequisite-patch-id: f332a4def1290bc364844d365a541cc651e461e1","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=YXsWu7Vy;\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=YXsWu7Vy","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.129.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 4fxV3Z1TNcz1yGt\n\tfor <incoming@patchwork.ozlabs.org>; Fri, 17 Apr 2026 06:29:14 +1000 (AEST)","from vm01.sourceware.org (localhost [127.0.0.1])\n\tby sourceware.org (Postfix) with ESMTP id 3ABEA4C9174E\n\tfor <incoming@patchwork.ozlabs.org>; Thu, 16 Apr 2026 20:29:12 +0000 (GMT)","from us-smtp-delivery-124.mimecast.com\n (us-smtp-delivery-124.mimecast.com [170.10.129.124])\n by sourceware.org (Postfix) with ESMTP id E24114BA2E04\n for <gcc-patches@gcc.gnu.org>; Thu, 16 Apr 2026 20:28:44 +0000 (GMT)","from mail-qv1-f71.google.com (mail-qv1-f71.google.com\n [209.85.219.71]) by relay.mimecast.com with ESMTP with STARTTLS\n (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id\n us-mta-59-vPTZ-habNFS7uhJRA1W31w-1; Thu, 16 Apr 2026 16:28:43 -0400","by mail-qv1-f71.google.com with SMTP id\n 6a1803df08f44-8a1accb970fso231914966d6.3\n for <gcc-patches@gcc.gnu.org>; Thu, 16 Apr 2026 13:28:43 -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 6a1803df08f44-8ae6c939211sm61499596d6.2.2026.04.16.13.28.40\n (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128);\n Thu, 16 Apr 2026 13:28:40 -0700 (PDT)"],"DKIM-Filter":["OpenDKIM Filter v2.11.0 sourceware.org 3ABEA4C9174E","OpenDKIM Filter v2.11.0 sourceware.org E24114BA2E04"],"DMARC-Filter":"OpenDMARC Filter v1.4.2 sourceware.org E24114BA2E04","ARC-Filter":"OpenARC Filter v1.0.0 sourceware.org E24114BA2E04","ARC-Seal":"i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1776371325; cv=none;\n b=NkY2RroP3pTzJJPMikfu/Arn/CLcc6jP58JeGIrkqtpYyR8+OpdlHayFxAJFcGrfEEf+yAQuZ4lSuUy9pLPTZQZB1iAKP85XqyRPMQ+VeUy+gosAFe8BnTRpo+p0QFYcxpnFzBtR7rqQp4GhxGQ7unDyvxfj+dfBsHWTacsAiII=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=sourceware.org; s=key;\n t=1776371325; c=relaxed/simple;\n bh=MHCFZkr7WkqaphR1/ZtWkzl36AhMDAEAld3q6i2HY/k=;\n h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From;\n b=nPkaIkiuRsILssU/vB9PpJ0XBgJWggEywMzZ8MCsZrDjG3e3IWuVkmOjs/VV03q6mg1sLB1yOyhJIY5b5zq2mz8gOL0owod6SpfwhxGEwZU95rnWKTgV/HnhQC/xufdl9Zgvo/YAHtX/VWSq38moJiECTLEy7osa5fI3JQd8v5s=","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=1776371324;\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=Apmj9QbXQvBq0KbY+OW/TVWdqN/1KuqeoSJtyVmhS2c=;\n b=YXsWu7VycZ3libsmCasXntQumq+/ZTUT3caCTdJfWxHdLDwgSm1Q6wjKn18BGmM5RjeLe5\n I8VERwyoXMPFLqfrSFZzoDWJVVh5U/8lfrRamTRUA5JlhvTDghFyGYn/TChWXPRH6wueq5\n cnPh/0OCdIg5Zlfae7ip03pHW1NA0gQ=","X-MC-Unique":"vPTZ-habNFS7uhJRA1W31w-1","X-Mimecast-MFC-AGG-ID":"vPTZ-habNFS7uhJRA1W31w_1776371323","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20251104; t=1776371322; x=1776976122;\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=Apmj9QbXQvBq0KbY+OW/TVWdqN/1KuqeoSJtyVmhS2c=;\n b=o3Uxz8nziRx0Dy4/pbAVb78eOLMsm24OekWWAH4cxVVgc6PdQAo+o/cFcEXYrttuWY\n 7Oo8oLLUPNdtWyUPYAMzTY0CFXsG64eyBb/ADDV39p7uoYoQj+BZx1lxsLXscFLikzZR\n IDOllzDFDoWrS0/bLVS0l9gSyLO0ozwflKnN5Lw8rf3EhO7EvA10ewcAiWK64OaCKX2o\n QbnNHvbDaq4/Sug4VhJ7AL1jJLBKaRmdUarfeA58PIKRTjaIFFZNhrgaVi3bKPaOxlxa\n inxhrEvT6OXg06vRmzGkqEioSgAMubsUF9ZjcHw4VFkwV4TRK6hskB0fuclXpRLQc716\n eRzw==","X-Gm-Message-State":"AOJu0YwNHv7fzOCUtVh6r+8Teg9qu6RbdH37NEwiD0AF4Fd9Ir2A1ucD\n jJLfYvJ+tq81pl/hR4MI6KE7N1gRwodg9P/KWXO85/4xb+2o35Vglr3Rw52nKgB8gQqWm5pL5PF\n zJDZUgalufe04ucO9prvGrG6TTLq2xuvN7ZmVv7Fgs4Aytc5oWkNFXRPWAnEm5O3DVIZWhQ==","X-Gm-Gg":"AeBDiesunCjHuVJQ2u93tkzMc//CwBGl110lOGXBrYid70ARDvgGKU7rBdvB3bZxBMk\n dnWKB0vCUOmYsirPmjb7XsCHhsWRsMrv92aa2TnvVzMLhe8IJsyKesIZBOiIFjYzwdIFsYNBjew\n g18WAkLNO3DBwvFBeqN1Y2QHO8OmW7/vfVR54oAeIXtuEiGtKfuZI7nK6F6Yt+Cw4rQDaBfIfz4\n fpa1jslUQ0hT0RZA+Ue5jXHYcoMnTKZW6fE2Yw55JQG/z8U6BfNHR0cEwDocGgUa6wLoQRDKfRi\n HzWcfjKmKRt9stf0Vwp+UtRr+U+sNn5kBq3+qCoDD4PGuff5OYGoh8IfPtKs85506ponITmd9uv\n rD1NzZwEoaeuLHSY+V2FtMzfs3PhixX7DUtJyHLpgF/6Oy3E+cDaY77ycJZvdra+PSbkBKh8met\n ki1YYqzjorZx0s0eYEL3cVT5UBKoxNO25UOGXHKBVQVA==","X-Received":["by 2002:a05:6214:4a90:b0:89c:4c6b:4615 with SMTP id\n 6a1803df08f44-8b027fd979fmr998126d6.8.1776371322080;\n Thu, 16 Apr 2026 13:28:42 -0700 (PDT)","by 2002:a05:6214:4a90:b0:89c:4c6b:4615 with SMTP id\n 6a1803df08f44-8b027fd979fmr997616d6.8.1776371321555;\n Thu, 16 Apr 2026 13:28:41 -0700 (PDT)"],"Message-ID":"<f451dea9-8d46-4ff3-8ab9-a055605b56b4@redhat.com>","Date":"Thu, 16 Apr 2026 16:28:39 -0400","MIME-Version":"1.0","User-Agent":"Mozilla Thunderbird","Subject":"Re: [PATCH v2] c++/reflection: splicing null reflection","To":"Marek Polacek <polacek@redhat.com>","Cc":"GCC Patches <gcc-patches@gcc.gnu.org>","References":"<20260415235200.1576761-1-polacek@redhat.com>\n <05317d8e-be32-4c67-8d50-becc3864e65e@redhat.com>\n <aeECjy5O6sXf2YA5@redhat.com>\n <dac6ba8a-3425-4993-8634-5a7aebe376b6@redhat.com>\n <aeFFooo_IfeHlQCw@redhat.com>","From":"Jason Merrill <jason@redhat.com>","In-Reply-To":"<aeFFooo_IfeHlQCw@redhat.com>","X-Mimecast-Spam-Score":"0","X-Mimecast-MFC-PROC-ID":"MzA0DW2NgT8Njv-oud8qRADRkaSNEjHa59vxkK7XUMk_1776371323","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"}}]