From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id 95BA6385802D for ; Tue, 5 Oct 2021 19:17:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 95BA6385802D Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-143-rBwmQOP8Pz-3IFXSXYS2PA-1; Tue, 05 Oct 2021 15:17:14 -0400 X-MC-Unique: rBwmQOP8Pz-3IFXSXYS2PA-1 Received: by mail-qv1-f72.google.com with SMTP id kc13-20020a056214410d00b00382bc805781so436817qvb.12 for ; Tue, 05 Oct 2021 12:17:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:date:to:cc:subject:in-reply-to:message-id :references:mime-version; bh=GG+UBF9dGqaCYGtAhRIngvrZ1przlHLCMZXk3+QFGh8=; b=J3WdaSfoYFO2ZWWGHk8SRQ1M2tDqDiyBc7yxkKXt3dolaDtEGnaDpFGsB9k/26d9JS BRBEK3lZx4aBRuWfjDPRtc43Et9XGm9IYosmsQtMuk2aIfwikt4ODVkhD3rBugZFQ5It e0y/3I6kPzNvzWBQGBUkfjDBl+vdLhe/DSa4sOVgWxc2mx7oNyX3eC8NVAtCp/+Hha+n z4Q/I04Y14QTy5ciFRmogdaTfJfNSbtrvVBu6ceCERwosJuc1Bs2GJGq3OvuFQaUy4pV Eqc3j38PoW+uFfuuG8iHoQdEp4sDNqeyHq1/B4gR7qtMzgnXgsxQmi6xmYujItnvKG1B P59g== X-Gm-Message-State: AOAM533jxDmRAF2YBJpzP9xxRPMq5OzMvZusVee/NoECgdVWd5xYBYA9 cGG1CqTiKBOBrWFYDdXq0oH2YCCkyEObQ+2oPTfjtfNwoq9MYPFDudg2gI8MhfJmJOTv66kEZ43 Z4yJM1ryrGcfZ/Kycrg== X-Received: by 2002:ac8:4084:: with SMTP id p4mr21826308qtl.306.1633461433967; Tue, 05 Oct 2021 12:17:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJygOVx70UBs5VseXi31FcBETLWS2T8dc7Bhg9E0XJiYTpgb00zBiZpDCNrWablrhAcA76Ki7w== X-Received: by 2002:ac8:4084:: with SMTP id p4mr21826288qtl.306.1633461433763; Tue, 05 Oct 2021 12:17:13 -0700 (PDT) Received: from [192.168.1.130] (ool-457d493a.dyn.optonline.net. [69.125.73.58]) by smtp.gmail.com with ESMTPSA id i18sm11941927qtx.60.2021.10.05.12.17.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Oct 2021 12:17:13 -0700 (PDT) From: Patrick Palka X-Google-Original-From: Patrick Palka Date: Tue, 5 Oct 2021 15:17:12 -0400 (EDT) To: Patrick Palka cc: gcc-patches@gcc.gnu.org, jason@redhat.com Subject: Re: [PATCH] c++: odr-use argument to a function NTTP [PR53164] In-Reply-To: <20211004164057.718456-1-ppalka@redhat.com> Message-ID: <5c3a3d47-9f97-7df-db59-7c8e592b0cb@idea> References: <20211004164057.718456-1-ppalka@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-16.0 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 05 Oct 2021 19:17:18 -0000 On Mon, 4 Oct 2021, Patrick Palka wrote: > When passing a function template as the argument to a function NTTP > inside a template, we resolve it to the right specialization ahead of > time via resolve_address_of_overloaded_function, though the call to > mark_used within defers odr-using it until instantiation time (as usual). > But at instantiation time we end up never calling mark_used on the > specialization. > > This patch fixes this by adding a call to mark_used in > convert_nontype_argument_function. > > PR c++/53164 > > gcc/cp/ChangeLog: > > * pt.c (convert_nontype_argument_function): Call mark_used. > > gcc/testsuite/ChangeLog: > > * g++.dg/template/non-dependent16.C: New test. > --- > gcc/cp/pt.c | 3 +++ > gcc/testsuite/g++.dg/template/non-dependent16.C | 16 ++++++++++++++++ > 2 files changed, 19 insertions(+) > create mode 100644 gcc/testsuite/g++.dg/template/non-dependent16.C > > diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c > index f950f4a21b7..5e819c9598c 100644 > --- a/gcc/cp/pt.c > +++ b/gcc/cp/pt.c > @@ -6668,6 +6668,9 @@ convert_nontype_argument_function (tree type, tree expr, > return NULL_TREE; > } > > + if (!mark_used (fn_no_ptr, complain) && !(complain & tf_error)) > + return NULL_TREE; > + > linkage = decl_linkage (fn_no_ptr); > if (cxx_dialect >= cxx11 ? linkage == lk_none : linkage != lk_external) > { > diff --git a/gcc/testsuite/g++.dg/template/non-dependent16.C b/gcc/testsuite/g++.dg/template/non-dependent16.C > new file mode 100644 > index 00000000000..b7dca8f6752 > --- /dev/null > +++ b/gcc/testsuite/g++.dg/template/non-dependent16.C > @@ -0,0 +1,16 @@ > +// PR c++/53164 > + > +template > +void f(T) { > + T::fail; // { dg-error "not a member" } > +} > + > +template > +struct A { }; > + > +template > +void g() { > + A a; > +} I should mention that the original testcase in the PR was slightly different than this one in that it also performed a call to the NTTP, e.g. template struct A { static void h() { p(0); } }; template void g() { A::h(); } templated void g<0>(); and not even the call was enough to odr-use f, apparently because the CALL_EXPR case of tsubst_expr calls mark_used on the callee only when it's a FUNCTION_DECL, but in this case after substitution it's an ADDR_EXPR of a FUNCTION_DECL. Fixing this by looking through the ADDR_EXPR worked, but IIUC the call isn't necessary for f to be odr-used, simply using f as a template argument should be sufficient, so it seems the above is better fix. > + > +template void g<0>(); > -- > 2.33.0.610.gcefe983a32 > >