From patchwork Fri Aug 28 16:40:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 1353375 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=qbtFgpJT; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BdQMm0Ddbz9sTK for ; Sat, 29 Aug 2020 02:41:07 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 64349394443C; Fri, 28 Aug 2020 16:41:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 64349394443C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1598632863; bh=INZzSiRI4g2muthNk26DcLJQ7bUMlDPAcYAaB+I3KWk=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=qbtFgpJTxuTDyY/8vK5HgHbvqrnjbeFhzieKIUHOOymiSk2CYhAUL2SjbejP6Bk0m GBffZEYPOXOu9xxh52VPm2WNfUwMmBkKl7jVUhixi9PWc9ceD5ensFpV/+iV6yGjjz 6mFMkxi1C2NK86y1DuKb/RK3sJxEhnggyEg73ulU= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) by sourceware.org (Postfix) with ESMTP id 2B5DD3861012 for ; Fri, 28 Aug 2020 16:41:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 2B5DD3861012 Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-217-7g3Sdi8iO2WLonhJ-1Ccjg-1; Fri, 28 Aug 2020 12:40:57 -0400 X-MC-Unique: 7g3Sdi8iO2WLonhJ-1Ccjg-1 Received: by mail-qt1-f197.google.com with SMTP id b18so1106179qte.18 for ; Fri, 28 Aug 2020 09:40:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=INZzSiRI4g2muthNk26DcLJQ7bUMlDPAcYAaB+I3KWk=; b=qagiVkC0crtCK5mcBB3nO54W2dOCN68jp7mvfn99OXd866vxjwmK1Put2dBw0ZYkqj jkrZia2FKzqzd8skaQD9RPaE0UozrTvycW/n+N+aPaonjHVvyJ4sJRdxMNjAcEWckE3x vlPdAe319sZ3MoZW1VZxxqQ4ywW1/ZEon+Dy1s2XlmHHX7pbe9qKQAynXYnE76+H9ENM b137k+bWCW6Hc1g+axDwy0HRTfD7ohV7QT/t5ghpBIer8vEQVCBmEtM5rEP2YB8VdMOA zqO48Z+cM06/675Vnsubv3AalPScir6PacBF0bfWaFbBQse+p6JRtzbs2M1Q+RVtgvkU SEtw== X-Gm-Message-State: AOAM530dNzXo7fHzcVdgQn6E+GNDiSY1+2n8U1O7EXBgB1V39EgTeMmw yVqPubdJ4sv8Xw8uM/QFC5d3x6aPKnP+qOCHmqbXbhVAXZTrYzuimJjiA7rFjwCC+yfAqELTWve 4+uOMCq7gb5y2JwV8yg== X-Received: by 2002:a05:620a:15f9:: with SMTP id p25mr1906339qkm.175.1598632856977; Fri, 28 Aug 2020 09:40:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJynDr9Aia9qlv8JFcFGpNDe92eLLzhslkkGlOQydJ1t3h5eGg+pBXIceZP+FMAGqCVYS0T4DQ== X-Received: by 2002:a05:620a:15f9:: with SMTP id p25mr1906316qkm.175.1598632856663; Fri, 28 Aug 2020 09:40:56 -0700 (PDT) Received: from localhost.localdomain (ool-457d493a.dyn.optonline.net. [69.125.73.58]) by smtp.gmail.com with ESMTPSA id f7sm1211963qkj.32.2020.08.28.09.40.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Aug 2020 09:40:55 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [PATCH] c++: Fix resolving the address of overloaded pmf [PR96647] Date: Fri, 28 Aug 2020 12:40:52 -0400 Message-Id: <20200828164052.2100771-1-ppalka@redhat.com> X-Mailer: git-send-email 2.28.0.358.g20de7e7e4f MIME-Version: 1.0 X-Mimecast-Spam-Score: 0.001 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-16.3 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_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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-Patchwork-Original-From: Patrick Palka via Gcc-patches From: Patrick Palka Reply-To: Patrick Palka Cc: libstdc++@gcc.gnu.org Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" In resolve_address_of_overloaded_function, currently only the second pass over the overload set (which considers just the function templates in the overload set) checks constraints and performs return type deduction when necessary. But as the testcases below show, we need to do this when considering non-template functions during the first pass, too. Tested on x86_64-pc-linux-gnu, does this look OK for trunk? gcc/cp/ChangeLog: PR c++/96647 * class.c (resolve_address_of_overloaded_function): Also check constraints and perform return type deduction when considering non-template functions in the overload set. gcc/testsuite/ChangeLog: PR c++/96647 * g++.dg/cpp0x/auto-96647.C: New test. * g++.dg/cpp2a/concepts-fn6.C: New test. --- gcc/cp/class.c | 16 ++++++++++++++++ gcc/testsuite/g++.dg/cpp0x/auto-96647.C | 10 ++++++++++ gcc/testsuite/g++.dg/cpp2a/concepts-fn6.C | 10 ++++++++++ 3 files changed, 36 insertions(+) create mode 100644 gcc/testsuite/g++.dg/cpp0x/auto-96647.C create mode 100644 gcc/testsuite/g++.dg/cpp2a/concepts-fn6.C diff --git a/gcc/cp/class.c b/gcc/cp/class.c index 3479b8207d2..c15cb04c654 100644 --- a/gcc/cp/class.c +++ b/gcc/cp/class.c @@ -8286,6 +8286,22 @@ resolve_address_of_overloaded_function (tree target_type, one, or vice versa. */ continue; + /* Constraints must be satisfied. This is done before + return type deduction since that instantiates the + function. */ + if (!constraints_satisfied_p (fn)) + continue; + + if (undeduced_auto_decl (fn)) + { + /* Force instantiation to do return type deduction. */ + ++function_depth; + instantiate_decl (fn, /*defer*/false, /*class*/false); + --function_depth; + + require_deduced_type (fn); + } + /* In C++17 we need the noexcept-qualifier to compare types. */ if (flag_noexcept_type && !maybe_instantiate_noexcept (fn, complain)) diff --git a/gcc/testsuite/g++.dg/cpp0x/auto-96647.C b/gcc/testsuite/g++.dg/cpp0x/auto-96647.C new file mode 100644 index 00000000000..314b2a16ac2 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/auto-96647.C @@ -0,0 +1,10 @@ +// PR c++/96647 +// { dg-do compile { target c++11 } } + +template +struct Base { + auto f(int) { } + auto f(char) { } +}; + +void (Base::*ptr)(int) = &Base::f; diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-fn6.C b/gcc/testsuite/g++.dg/cpp2a/concepts-fn6.C new file mode 100644 index 00000000000..3d7941658d4 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-fn6.C @@ -0,0 +1,10 @@ +// PR c++/96647 +// { dg-do compile { target c++20 } } + +template +struct Base { + auto f(int) { } + auto f(int) requires T::fail { static_assert(T::fail); } +}; + +void (Base::*ptr)(int) = &Base::f;