[{"id":3680728,"web_url":"http://patchwork.ozlabs.org/comment/3680728/","msgid":"<0ee0590a-3c48-6588-dfdf-10ed0fd511fb@idea>","list_archive_url":null,"date":"2026-04-22T17:43:30","subject":"Re: [PATCH] c++/reflection: reflect on dependent class template\n [PR124926]","submitter":{"id":78319,"url":"http://patchwork.ozlabs.org/api/people/78319/","name":"Patrick Palka","email":"ppalka@redhat.com"},"content":"On Wed, 22 Apr 2026, Marek Polacek wrote:\n\n> Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?\n> \n> -- >8 --\n> Here we issue a bogus error for\n> \n>   ^^Cls<T>::template Inner\n> \n> where Inner turns out to be a class type, but we created a SCOPE_REF\n> because we can't know in advance what it will substitute into, and\n> \n>   ^^typename Cls<T>::template Inner\n> \n> is invalid.  The typename can only be used in\n> \n>   ^^typename Cls<T>::template Inner<int>\n> \n> We're taking a reflection so both types and non-types are valid, so\n> I think we shouldn't give the error for ^^, and take the reflection\n> of the TEMPLATE_DECL.\n> \n> \tPR c++/124926\n> \n> gcc/cp/ChangeLog:\n> \n> \t* pt.cc (tsubst_qualified_id): New bool parameter.  Don't give the\n> \t\"instantiation yields a type\" error when the new parameter is true.\n> \t(tsubst_expr) <case REFLECT_EXPR>: Adjust the call to\n> \ttsubst_qualified_id.\n> \n> gcc/testsuite/ChangeLog:\n> \n> \t* g++.dg/reflect/dep15.C: New test.\n> ---\n>  gcc/cp/pt.cc                         | 13 +++--\n>  gcc/testsuite/g++.dg/reflect/dep15.C | 85 ++++++++++++++++++++++++++++\n>  2 files changed, 94 insertions(+), 4 deletions(-)\n>  create mode 100644 gcc/testsuite/g++.dg/reflect/dep15.C\n> \n> diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc\n> index 5d97ca7997f..f73805b2557 100644\n> --- a/gcc/cp/pt.cc\n> +++ b/gcc/cp/pt.cc\n> @@ -18238,12 +18238,14 @@ tsubst_baselink (tree baselink, tree object_type,\n>     true if the qualified-id will be a postfix-expression in-and-of\n>     itself; false if more of the postfix-expression follows the\n>     QUALIFIED_ID.  ADDRESS_P is true if the qualified-id is the operand\n> -   of \"&\".  NAME_LOOKUP_P is true if we intend to perform name lookup.  */\n> +   of \"&\".  NAME_LOOKUP_P is true if we intend to perform name lookup.\n> +   REFLECTING_P is true if this SCOPE_REF is an operand of ^^.  */\n>  \n>  static tree\n>  tsubst_qualified_id (tree qualified_id, tree args,\n>  \t\t     tsubst_flags_t complain, tree in_decl,\n> -\t\t     bool done, bool address_p, bool name_lookup_p = true)\n> +\t\t     bool done, bool address_p, bool name_lookup_p = true,\n> +\t\t     bool reflecting_p = false)\n>  {\n>    tree expr;\n>    tree scope;\n> @@ -18322,7 +18324,9 @@ tsubst_qualified_id (tree qualified_id, tree args,\n>        else\n>  \texpr = lookup_qualified_name (scope, expr, LOOK_want::NORMAL, false);\n>        if (TREE_CODE (TREE_CODE (expr) == TEMPLATE_DECL\n> -\t\t     ? DECL_TEMPLATE_RESULT (expr) : expr) == TYPE_DECL)\n> +\t\t     ? DECL_TEMPLATE_RESULT (expr) : expr) == TYPE_DECL\n> +\t  /* For ^^T::X, we'll take both types and non-types.  */\n> +\t  && !reflecting_p)\n>  \t{\n>  \t  if (complain & tf_error)\n>  \t    {\n> @@ -23355,7 +23359,8 @@ tsubst_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl)\n>  \telse if (TREE_CODE (h) == SCOPE_REF)\n>  \t  h = tsubst_qualified_id (h, args, complain, in_decl,\n>  \t\t\t\t   /*done=*/true, /*address_p=*/false,\n> -\t\t\t\t   /*name_lookup_p=*/false);\n> +\t\t\t\t   /*name_lookup_p=*/false,\n> +\t\t\t\t   /*reflecting_p=*/true);\n\nShould we just merge name_lookup_p with reflecting_p at this point?\nMore descriptive flag names are nice but having fewer flags is also nice :)\nAnd at first glance name_lookup_p doesn't seem precisely named, there\nare name lookup calls in tsubst_qualified_id that aren't suppressed by\nthat flag (such as the ones immediately before the error in question).\n\n\n>  \telse\n>  \t  {\n>  \t    /* [expr.reflect] The id-expression of a reflect-expression is\n> diff --git a/gcc/testsuite/g++.dg/reflect/dep15.C b/gcc/testsuite/g++.dg/reflect/dep15.C\n> new file mode 100644\n> index 00000000000..40273955164\n> --- /dev/null\n> +++ b/gcc/testsuite/g++.dg/reflect/dep15.C\n> @@ -0,0 +1,85 @@\n> +// PR c++/124926\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> +// Class template\n> +template <typename>\n> +struct C1 {\n> +  template <typename> struct Inner {};\n> +};\n> +\n> +template <typename T>\n> +constexpr auto vt1 = ^^C1<T>::template Inner;\n> +constexpr auto r1 = vt1<int>;\n> +typename [:r1:]<int> a;\n> +static_assert(r1 == ^^C1<int>::template Inner);\n> +static_assert(is_same_v<decltype(a), C1<int>::Inner<int>>);\n> +\n> +// Class template with typename\n> +template <typename>\n> +struct C6 {\n> +  template <typename> struct Inner {};\n> +};\n> +\n> +template <typename T>\n> +constexpr auto vt6 = ^^typename C6<T>::template Inner<T>;\n> +constexpr auto r6 = vt6<int>;\n> +typename [:r6:] d;\n> +static_assert(r6 == ^^C6<int>::template Inner<int>);\n> +static_assert(is_same_v<decltype(d), C6<int>::Inner<int>>);\n> +\n> +// Variable template\n> +template <typename>\n> +struct C2 {\n> +  template <typename> static constexpr int Inner = 42;\n> +};\n> +\n> +template <typename T>\n> +constexpr auto vt2 = ^^C2<T>::template Inner;\n> +constexpr auto r2 = vt2<int>;\n> +constexpr int i = template [:r2:]<int>;\n> +static_assert(i == 42);\n> +static_assert(vt2<int> == ^^C2<int>::template Inner);\n> +\n> +// Function template\n> +template <typename>\n> +struct C3 {\n> +  template <typename T> static constexpr int Inner (T t) { return t; };\n> +};\n> +template <typename T>\n> +constexpr auto vt3 = ^^C3<T>::template Inner;\n> +constexpr auto r3 = vt3<int>;\n> +static_assert(template [:r3:](42) == 42);\n> +static_assert(vt3<int> == ^^C3<int>::template Inner);\n> +\n> +// Alias template\n> +template <typename>\n> +struct C4 {\n> +  template <typename T> using Inner = C4<T>;\n> +};\n> +template <typename T>\n> +constexpr auto vt4 = ^^C4<T>::template Inner;\n> +constexpr auto r4 = vt4<int>;\n> +typename [:r4:]<int> b;\n> +static_assert(is_same_v<decltype(b), C4<int>>);\n> +static_assert(vt4<int> == ^^C4<int>::template Inner);\n> +\n> +// Alias template with typename\n> +template<typename T> struct X { };\n> +\n> +template <typename>\n> +struct C5 {\n> +  template <typename T> using Inner = X<T>;\n> +};\n> +template <typename T>\n> +constexpr auto vt5 = ^^typename C5<T>::template Inner<T>;\n> +constexpr auto r5 = vt5<int>;\n> +typename [:r5:] c;\n> +static_assert(is_same_v<decltype(c), X<int>>);\n> +static_assert(vt5<int> == ^^C5<int>::template Inner<int>);\n> \n> base-commit: cb70dab0e4bfa94e009700086001a5b2dc17ea5d\n> -- \n> 2.53.0\n> \n>","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=HfsuirYe;\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=HfsuirYe","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 4g166G2hmzz1yGs\n\tfor <incoming@patchwork.ozlabs.org>; Thu, 23 Apr 2026 03:44:05 +1000 (AEST)","from vm01.sourceware.org (localhost [127.0.0.1])\n\tby sourceware.org (Postfix) with ESMTP id 115F94BB3BC8\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 22 Apr 2026 17:44:03 +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 8CC7B4BAD159\n for <gcc-patches@gcc.gnu.org>; Wed, 22 Apr 2026 17:43:34 +0000 (GMT)","from mail-qk1-f198.google.com (mail-qk1-f198.google.com\n [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS\n (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id\n us-mta-644-4Lxr3e3LMjGwmAs6OhpmFQ-1; Wed, 22 Apr 2026 13:43:33 -0400","by mail-qk1-f198.google.com with SMTP id\n af79cd13be357-8eb6880430dso104685985a.2\n for <gcc-patches@gcc.gnu.org>; Wed, 22 Apr 2026 10:43:33 -0700 (PDT)","from [2600:4040:aa66:bf00:9e8e:99ff:fed1:71f]\n ([2600:4040:aa66:bf00:9e8e:99ff:fed1:71f])\n by smtp.gmail.com with ESMTPSA id\n af79cd13be357-8e7d5fe90afsm1607271285a.3.2026.04.22.10.43.30\n (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n Wed, 22 Apr 2026 10:43:31 -0700 (PDT)"],"DKIM-Filter":["OpenDKIM Filter v2.11.0 sourceware.org 115F94BB3BC8","OpenDKIM Filter v2.11.0 sourceware.org 8CC7B4BAD159"],"DMARC-Filter":"OpenDMARC Filter v1.4.2 sourceware.org 8CC7B4BAD159","ARC-Filter":"OpenARC Filter v1.0.0 sourceware.org 8CC7B4BAD159","ARC-Seal":"i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1776879814; cv=none;\n b=aa5eOEPuIT6FustmY0L4waKFAY6it1yZ1u0jjhBRxitWT3y0/QNzcNkygeIU8gFh9hTcJqcMlYYO4xy37VyFKbhp0yF1ZoRhiGnLbe8P4z/mYAVLq1/xsaMUK7oxLOj4xVnyOaSkxKAbuZue2/5q5MlWDr+g3tMGICY7pfs7zTU=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=sourceware.org; s=key;\n t=1776879814; c=relaxed/simple;\n bh=3t4qBYt3h5LnsKhclHkzzHc9IFCPfx1JZNVFAfXDpos=;\n h=DKIM-Signature:From:Date:To:Subject:Message-ID:MIME-Version;\n b=dgogEyhTK4HIJiDaSaklFo2caCNeb0HS8kglf1fg3mR+lLK9TgdDbZYmfq4g7xymgCsUacepeoYZK0O1+92Bo/v5b+pe5GG4Pzr9jQkTvaUDd6LywmTks5A0G6tOxJkKnDQS29WVgTC33Jo7knRcsLmjlPhXQlgOcx7hvjLDYD4=","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=1776879814;\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 in-reply-to:in-reply-to:references:references;\n bh=9JUAcYZd3HpJp1aypRsscMfF3cZhebQBSNY/UmM/WV8=;\n b=HfsuirYeQfbRRMOKJnHiOB0hW1pq2xgKPfZZLNP2UopxcCe4y7EPJ/IeN4tsKjVoQEQVMf\n mIYjgtJ+A9T01AdBVPP+lzWjrwZ1NvBlMoPVkH7w/IJw++fFs0EJo81SnwdnJkng0iZV4X\n +ZhdOHcsIrCiZDxYeZ3ZgPJ8CqJ/ezI=","X-MC-Unique":"4Lxr3e3LMjGwmAs6OhpmFQ-1","X-Mimecast-MFC-AGG-ID":"4Lxr3e3LMjGwmAs6OhpmFQ_1776879812","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20251104; t=1776879812; x=1777484612;\n h=mime-version:references:message-id:in-reply-to:subject:cc:to:date\n :from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id\n :reply-to;\n bh=9JUAcYZd3HpJp1aypRsscMfF3cZhebQBSNY/UmM/WV8=;\n b=TOGtZOVK2Zj1YY8DmPNc4TcLNLBRJ23as0UxtHvbDTFeHolvrPjsqlYaG9YJWrSWZG\n Ph1ISCp+Xm2TOQJKC1OYbZHpQ6b7uRmq+9hLtaWW+y3uByYe6n8i1Snt/VCLLKw0t0AT\n TcNNMwDXjK/jA7K2eXNN9Hjd1C325VtFS5Gt/LrBzoIe7sUMzNrLH2awC77e/nJ0v4+k\n X3sBasi8rQwCpJM0kGwEjTzGvP6VDTKfipaGivFXkNGEw/fxavFmE2h9cBDkSx4MOZcd\n 2/OcZXTLWKZsXRpIoZPgcUjF2FGnGbYpTqJwXJfI0zJYcIrwn6gDFzV0nOnqEKgjL4rx\n 27NQ==","X-Gm-Message-State":"AOJu0YwiUx0IkJLQL/iB5vq6sKPT0GPLzM8yCv3joMNgV61pvX3W8XLg\n njsRlsrw7JsgDucfbs0LL7ePsxoDvBZhDEBWqia8MwLLbrxJGDX0f8FONXhsLc0MtDZK03DIJAP\n tU1n+VdYz2YIOURFn3WZwLnykhcExF+YDnEk3jPrAmEJMcE9FLeGgo8MBZDU=","X-Gm-Gg":"AeBDiet9vTzjtypNxIb/GKrSSS+FxrY5TEkXuKhvhE0ZZdyV95mprjrVXxhViHAfsx1\n MokwnCvbGfwBD/t0PxjRX51t1KsCvrz3r317UzaIrlRnLptZKYag/vPvuJdas/jNFSJ76ZN58Jp\n TC6d+GGLEK/BuYp+jvPYh+TTggy4SYHS6MrDhMYyoob7/wcpO6nZL7TZJNip1mTSgsy9oJRpAGN\n OBrwkbAL6ZJbNbYl9kfdMzT4ZpFSnlSV/V96u/vHV5dCU/S2c2ITvdMWpCNutfQRFeFTSl36EV0\n zujFBGtWSqBKJzy6QF76xyaX4cVfmLtdUqTOYhCOXIQTDaduqJBsbrhxuIPnauvQepk0MOKkNHd\n SLv+4VaDJ70pAmjLyw4FonJhuNz0PWZiUKUCk0W05qRNyAJYVItaJrBcv3vVvYvjM","X-Received":["by 2002:a05:620a:4114:b0:8f0:7516:da94 with SMTP id\n af79cd13be357-8f07516e2aamr185420985a.1.1776879812405;\n Wed, 22 Apr 2026 10:43:32 -0700 (PDT)","by 2002:a05:620a:4114:b0:8f0:7516:da94 with SMTP id\n af79cd13be357-8f07516e2aamr185417385a.1.1776879811773;\n Wed, 22 Apr 2026 10:43:31 -0700 (PDT)"],"From":"Patrick Palka <ppalka@redhat.com>","X-Google-Original-From":"Patrick Palka <patrick@idea>","Date":"Wed, 22 Apr 2026 13:43:30 -0400 (EDT)","To":"Marek Polacek <polacek@redhat.com>","cc":"GCC Patches <gcc-patches@gcc.gnu.org>, Jason Merrill <jason@redhat.com>","Subject":"Re: [PATCH] c++/reflection: reflect on dependent class template\n [PR124926]","In-Reply-To":"<20260422172510.801133-1-polacek@redhat.com>","Message-ID":"<0ee0590a-3c48-6588-dfdf-10ed0fd511fb@idea>","References":"<20260422172510.801133-1-polacek@redhat.com>","MIME-Version":"1.0","X-Mimecast-Spam-Score":"0","X-Mimecast-MFC-PROC-ID":"A-KCiWA-VnetfBXyQCtppPtsWVi_slnwyHGTEjJUO7o_1776879812","X-Mimecast-Originator":"redhat.com","Content-Type":"text/plain; charset=US-ASCII","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"}}]