From patchwork Thu Aug 6 17:52:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 1341853 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=2620:52:3:1:0:246e:9693:128c; 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=JTOGnIVp; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (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 4BMx0Q6gnXz9sSG for ; Fri, 7 Aug 2020 03:52:38 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6BADE388A83A; Thu, 6 Aug 2020 17:52:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6BADE388A83A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1596736356; bh=Dr9iUNToO97Xht+7fzDQXygTCDPabbAPiDbn1sC6Lgc=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=JTOGnIVprAIe71UdKulVr5oeTwBbS9V3fBYPhWl0uNaqKR6V/sN//iFe2NWEZauni iQcsRpHzbDAAnUzJLh67oCHQHFtg0gIlQn3uck9QsssfN9ocfJchHj1vR14X5SIRHg dypGmj230ug1JQUKyKmYRbN3Xihemw0OFAm2aEwg= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by sourceware.org (Postfix) with ESMTP id 31603388A826 for ; Thu, 6 Aug 2020 17:52:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 31603388A826 Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-90-qMT2WiaGNpiV2DJIWidfPg-1; Thu, 06 Aug 2020 13:52:32 -0400 X-MC-Unique: qMT2WiaGNpiV2DJIWidfPg-1 Received: by mail-qt1-f198.google.com with SMTP id p22so1284429qtp.9 for ; Thu, 06 Aug 2020 10:52:32 -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=Dr9iUNToO97Xht+7fzDQXygTCDPabbAPiDbn1sC6Lgc=; b=O0M3TEk+4zDd9iJjmNClTSRr8soBMpzPj5efqQ/NWzVq7rouioRbbtymhXrHQyURBO vLCmYatW/pT7lfRPfYV14tln8Qqv12z2NuSTqo5b1KpfldG+0zHENY2ykrsBrRhh8nIi U55sjZO2SyspNLsjnK1qUasdxlfZUpuDhUVZl5G3W0Upb8uiLbOAkBN97BYLF5n81+e/ JjqLWj8yk9TLCMvzrHFbba/9ERZHcmJQJI6VBpjJBHrdrin06QocsRpK67jNnDjqrQmS BadEHOFOtRm3/h+bJHxZVCHwJ9667EYR+HSsaTxJuwpFFxOpHFnn702qUfyIg34/XiBL FiWA== X-Gm-Message-State: AOAM531l/NgcFcSASj8vicQSO5SXY4m72Af/lSOLQpAQjUDHpgV/d8c2 d9PHHkxWHrfEVc/bdLhdG/DD0sGS1H7ugxc0EiJaEbp92uF7S46PPlg72/3ZnZMiyKFQ+b8hOZQ FgLiO+Z5T0iF5ClUUiw== X-Received: by 2002:ac8:4707:: with SMTP id f7mr10289665qtp.22.1596736351423; Thu, 06 Aug 2020 10:52:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxX/JqXEJscVb6+9MsXC1glN34OiEPnBhn3F1tWUMvcNE0A4Ns+SfT/4RNFeBLj3nbm/+fcGg== X-Received: by 2002:ac8:4707:: with SMTP id f7mr10289649qtp.22.1596736351194; Thu, 06 Aug 2020 10:52:31 -0700 (PDT) Received: from localhost.localdomain (ool-457d493a.dyn.optonline.net. [69.125.73.58]) by smtp.gmail.com with ESMTPSA id q68sm4448257qke.123.2020.08.06.10.52.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Aug 2020 10:52:30 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [PATCH] c++: constraints and address of template-id Date: Thu, 6 Aug 2020 13:52:21 -0400 Message-Id: <20200806175221.3522941-1-ppalka@redhat.com> X-Mailer: git-send-email 2.28.0.97.gdc04167d37 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 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 Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" When resolving the address of a template-id, we need to drop functions whose associated constraints are not satisfied, as per [over.over]. We do so in resolve_address_of_overloaded_function, but not in resolve_overloaded_unification or resolve_nondeduced_context, which seems like an oversight. Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK to commit? gcc/cp/ChangeLog: * pt.c (resolve_overloaded_unification): Drop functions with unsatisfied constraints. (resolve_nondeduced_context): Likewise. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/concepts-fn5.C: New test. * g++.dg/concepts/fn8.C: Generalize dg-error directive to accept "no matching function ..." diagnostic. * g++.dg/cpp2a/concepts-fn1.C: Likewise. * g++.dg/cpp2a/concepts-ts2.C: Likewise. * g++.dg/cpp2a/concepts-ts3.C: Likewise. --- gcc/cp/pt.c | 5 ++++- gcc/testsuite/g++.dg/concepts/fn8.C | 2 +- gcc/testsuite/g++.dg/cpp2a/concepts-fn1.C | 2 +- gcc/testsuite/g++.dg/cpp2a/concepts-fn5.C | 16 ++++++++++++++++ gcc/testsuite/g++.dg/cpp2a/concepts-ts2.C | 2 +- gcc/testsuite/g++.dg/cpp2a/concepts-ts3.C | 2 +- 6 files changed, 24 insertions(+), 5 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp2a/concepts-fn5.C diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index e7496002c1c..bcfe8d146b1 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -22122,6 +22122,8 @@ resolve_overloaded_unification (tree tparms, && !any_dependent_template_arguments_p (subargs)) { fn = instantiate_template (fn, subargs, tf_none); + if (!constraints_satisfied_p (fn)) + continue; if (undeduced_auto_decl (fn)) { /* Instantiate the function to deduce its return type. */ @@ -22268,7 +22270,8 @@ resolve_nondeduced_context (tree orig_expr, tsubst_flags_t complain) badfn = fn; badargs = subargs; } - else if (elem && (!goodfn || !decls_match (goodfn, elem))) + else if (elem && (!goodfn || !decls_match (goodfn, elem)) + && constraints_satisfied_p (elem)) { goodfn = elem; ++good; diff --git a/gcc/testsuite/g++.dg/concepts/fn8.C b/gcc/testsuite/g++.dg/concepts/fn8.C index ed900809908..32df5a556c0 100644 --- a/gcc/testsuite/g++.dg/concepts/fn8.C +++ b/gcc/testsuite/g++.dg/concepts/fn8.C @@ -24,5 +24,5 @@ template void g(T x) { } int main () { - g(&f); // { dg-error "no matches" } + g(&f); // { dg-error "no match" } } diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-fn1.C b/gcc/testsuite/g++.dg/cpp2a/concepts-fn1.C index 238eb819e90..b31675d255c 100644 --- a/gcc/testsuite/g++.dg/cpp2a/concepts-fn1.C +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-fn1.C @@ -170,7 +170,7 @@ template void g(T x) { } void driver_3 () { g(&ok); - g(&err); // { dg-error "no matches" } + g(&err); // { dg-error "no match" } } diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-fn5.C b/gcc/testsuite/g++.dg/cpp2a/concepts-fn5.C new file mode 100644 index 00000000000..c01cedde28e --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-fn5.C @@ -0,0 +1,16 @@ +// Verify we check constraints when resolving the address of a template-id. +// { dg-do compile { target c++20 } } + +void id(auto) { } + +template +int f() { return 0; } + +template requires requires { T::fail(); } +auto f() { T::fail(); } + +int main() { + using U = decltype(&f); + (void)&f; + id(&f); +} diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-ts2.C b/gcc/testsuite/g++.dg/cpp2a/concepts-ts2.C index d28002c035a..5942ff19327 100644 --- a/gcc/testsuite/g++.dg/cpp2a/concepts-ts2.C +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-ts2.C @@ -173,7 +173,7 @@ template void g(T x) { } void driver_3 () { g(&ok); - g(&err); // { dg-error "no matches" } + g(&err); // { dg-error "no match" } } diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-ts3.C b/gcc/testsuite/g++.dg/cpp2a/concepts-ts3.C index 9d47a7a083d..6f7ed1ffee4 100644 --- a/gcc/testsuite/g++.dg/cpp2a/concepts-ts3.C +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-ts3.C @@ -173,7 +173,7 @@ template void g(T x) { } void driver_3 () { g(&ok); - g(&err); // { dg-error "no matches" } + g(&err); // { dg-error "no match" } }