From patchwork Fri Feb 5 21:36:56 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 579635 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 5DB5C140BCB for ; Sat, 6 Feb 2016 08:37:10 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=aAyZyJ/C; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :date:to:cc:subject:in-reply-to:message-id:references :mime-version:content-type; q=dns; s=default; b=p2oW/HM5hMMLtLiw Ah7lOa4Vl7kUEwEwX2w7OpELsu5stlAOGgGEo+hvob2O6yETSn3JUSl5boUpQyD5 RlpS3FDp583oja4NVZcwW+tXIs6+it7bIK6EIYTjfeT7FcXxaEx7xk7KDOg0Vgfo yiAhPBlLw3vZlCmnmlekhrniuXg= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :date:to:cc:subject:in-reply-to:message-id:references :mime-version:content-type; s=default; bh=AyeMSNjF6Kgr5T2yqO3SsF 3wUyc=; b=aAyZyJ/Cp2unSfJwIBPH+YQSzD7YMEcrbhC3C7M8KJl6YFZteSIpsY KDRc0SeUoOhc0bOvcZLaI2nKyif5NMCINlDFNgAC7B7FMQ3TCHa+ngLUh1WFaMDK BrMcwAoYXA19aCfugmBthS1FeM+xU7bikON7ZaIr+s2O1CVcq7bPI= Received: (qmail 50148 invoked by alias); 5 Feb 2016 21:37:02 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 50136 invoked by uid 89); 5 Feb 2016 21:37:01 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 spammy=adl, ape, decl2c, decl2.c X-HELO: mail-qg0-f52.google.com Received: from mail-qg0-f52.google.com (HELO mail-qg0-f52.google.com) (209.85.192.52) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Fri, 05 Feb 2016 21:37:00 +0000 Received: by mail-qg0-f52.google.com with SMTP id b35so78376897qge.0 for ; Fri, 05 Feb 2016 13:37:00 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:date:to:cc:subject:in-reply-to:message-id :references:user-agent:mime-version:content-type; bh=gjRd/CUD1rwLPwkRZwME9C2k4u3xACLqIn//aE7n6u0=; b=dX65O4tLhO39NEaL19R6r3blINEN44NrammnqMalM1BHJfLS1Gtj41u+Del0S4Vtss /dMNG6f+S0odh+2FaOqZ56Z+V5dskvt3LZtTBG6W5jlPtsKxHucvbP3yqWHDeGhISwIm TJ1lZW4WCf9O9uv8Fo/7ML00ybHLfX5Obhel2pDQtgqva+k/BdqqVXfxl4fG5A0FT195 pGBwZs+fqqoI0uxjxj0JYVAAnrR3HAAjIh26EcYZp/mab0DA9FW2pQLL+fZIxecV+8Mt U96ZI1VWvJtGeqTT7C8ltd/ionuZnclGepIrEQrvoXD/XjlWrIGkfSRSs9D9Xk15e2yk WyDQ== X-Gm-Message-State: AG10YOTu2zRxj5she/nk8SJ1u21bm0UfZZnU1WmwtL+VtOPHHS1J+UiAJnEgT+PWydqMwQ== X-Received: by 10.141.6.130 with SMTP id i124mr20476418qhd.90.1454708218706; Fri, 05 Feb 2016 13:36:58 -0800 (PST) Received: from [192.168.1.130] (ool-4353abbc.dyn.optonline.net. [67.83.171.188]) by smtp.gmail.com with ESMTPSA id 200sm8821196qhm.47.2016.02.05.13.36.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 05 Feb 2016 13:36:57 -0800 (PST) From: Patrick Palka X-Google-Original-From: Patrick Palka Date: Fri, 5 Feb 2016 16:36:56 -0500 (EST) To: Patrick Palka cc: Jason Merrill , GCC Patches Subject: Re: [PATCH] Fix PR c++/69283 (auto deduction fails when ADL is required) In-Reply-To: Message-ID: References: <1453175728-13354-1-git-send-email-patrick@parcs.ath.cx> <569E4E8F.4000701@redhat.com> User-Agent: Alpine 2.20.9 (DEB 106 2015-09-22) MIME-Version: 1.0 On Tue, 19 Jan 2016, Patrick Palka wrote: > On Tue, Jan 19, 2016 at 9:56 AM, Jason Merrill wrote: >> On 01/18/2016 10:55 PM, Patrick Palka wrote: >>> >>> mark_used is wrongly diagnosing a use of a TEMPLATE_DECL (e.g. the call >>> to f1 in function f3 of auto-fn29.C below) for having an undeduced >>> 'auto' return type. This doesn't make sense, because an 'auto' used >>> inside a template doesn't get deduced until after the template is >>> instantiated. So for a TEMPLATE_DECL we shouldn't diagnose a use of >>> undeduced 'auto' here. After instantiation, presumably we will call >>> mark_used on the resulting FUNCTION_DECL which will check for undeduced >>> auto appropriately. >>> @@ -5112,7 +5112,9 @@ mark_used (tree decl, tsubst_flags_t complain) >>> || DECL_LANG_SPECIFIC (decl) == NULL >>> || DECL_THUNK_P (decl)) >>> { >>> - if (!processing_template_decl && type_uses_auto (TREE_TYPE (decl))) >>> + if (!processing_template_decl >>> + && TREE_CODE (decl) != TEMPLATE_DECL >>> + && type_uses_auto (TREE_TYPE (decl))) >> >> >> How does a TEMPLATE_DECL get in here? Does it have null DECL_LANG_SPECIFIC? > > (In the test case auto-fn29.C,) When instantiating the template > function f3,we call tsubst on the CALL_EXPR "f1 (v);". There, ADL is > performed on the identifier f1 (which is the CALL_EXPR_FN) which > returns the TEMPLATE_DECL f1. Then mark_used is called on this > CALL_EXPR_FN, only if it's a decl. > > If in the test case the call to "f1 (v);" is replaced with "Ape::f1 > (v);" then the CALL_EXPR_FN is then an OVERLOAD (to the TEMPLATE_DECL > f1), i.e. not a decl, so we don't call mark_used on it in tsubst. > > The DECL_LANG_SPECIFIC of this decl is not null. > >> >> I'd think mark_used of a TEMPLATE_DECL should return after setting >> TREE_USED, there's nothing else to do with it. > > Consider it changed. Here's the updated patch, with mark_used made to return earlier in case of a TEMPLATE_DECL. Also, auto-fn31.C is now consolidated into auto-fn29.C since the two test cases were so similar. -- >8 -- gcc/cp/ChangeLog: PR c++/69283 PR c++/67835 * decl2.c (mark_used): When given a TEMPLATE_DECL, return after setting its TREE_USED. gcc/testsuite/ChangeLog: PR c++/69283 PR c++/67835 * g++.dg/cpp1y/auto-fn29.C: New test. * g++.dg/cpp1y/auto-fn30.C: New test. --- gcc/cp/decl2.c | 4 ++++ gcc/testsuite/g++.dg/cpp1y/auto-fn29.C | 34 ++++++++++++++++++++++++++++++++++ gcc/testsuite/g++.dg/cpp1y/auto-fn30.C | 21 +++++++++++++++++++++ 3 files changed, 59 insertions(+) create mode 100644 gcc/testsuite/g++.dg/cpp1y/auto-fn29.C create mode 100644 gcc/testsuite/g++.dg/cpp1y/auto-fn30.C diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c index 7d68961..15d7617 100644 --- a/gcc/cp/decl2.c +++ b/gcc/cp/decl2.c @@ -5068,6 +5068,10 @@ mark_used (tree decl, tsubst_flags_t complain) /* Set TREE_USED for the benefit of -Wunused. */ TREE_USED (decl) = 1; + + if (TREE_CODE (decl) == TEMPLATE_DECL) + return true; + if (DECL_CLONED_FUNCTION_P (decl)) TREE_USED (DECL_CLONED_FUNCTION (decl)) = 1; diff --git a/gcc/testsuite/g++.dg/cpp1y/auto-fn29.C b/gcc/testsuite/g++.dg/cpp1y/auto-fn29.C new file mode 100644 index 0000000..f9260e0 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1y/auto-fn29.C @@ -0,0 +1,34 @@ +// PR c++/69283 +// { dg-do compile { target c++14 } } + +namespace Ape { + struct Type {}; + + template + auto f1(T const& v){ + return true; + } + + template + auto f2(T const& v){ + return f2(v); // { dg-error "auto" } + } +} + +namespace Baboon { + template + bool f3(T const& v){ + return f1(v); + } + + template + bool f4(T const& v){ + f2(v); + } +} + +int main(){ + Ape::Type x; + Baboon::f3(x); + Baboon::f4(x); +} diff --git a/gcc/testsuite/g++.dg/cpp1y/auto-fn30.C b/gcc/testsuite/g++.dg/cpp1y/auto-fn30.C new file mode 100644 index 0000000..e005e6e --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1y/auto-fn30.C @@ -0,0 +1,21 @@ +// PR c++/67835 +// { dg-do compile { target c++14 } } + +template +auto g(Tag tag, T x) { + return f(tag, x); +} + +namespace abc { +struct tag {}; + +struct A {}; + +template +auto f(tag, T x) { return x; } +} + +int main() { + g(abc::tag(), abc::A()); + return 0; +}