From patchwork Sat Apr 4 15:06:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Pan2 via Gcc-patches" X-Patchwork-Id: 1266417 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=ASNjD7+w; 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 48vgB544Drz9sSG for ; Sun, 5 Apr 2020 02:06:37 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8B9D6385DC1B; Sat, 4 Apr 2020 15:06:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8B9D6385DC1B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1586012794; bh=xz6xKYOsYoQmw8MBJXRsWjwuPdiLqIJbthdCmCVs1CY=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=ASNjD7+wog9+jm/eeH/oPw3ZamKKoA78He4icezlfdu2E0BwnAqbaPb46Lqp8740z xiAs59S14tcBvrE7MjdBVmuhRkov+YzDBL3nzkYpUU28Ni7DubU457bkoTfv3oWG9R reI7WNIUwSYdXV9t48hQUjZcSdYE8pXww9POEty4= 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 [207.211.31.120]) by sourceware.org (Postfix) with ESMTP id 40334385DC1A for ; Sat, 4 Apr 2020 15:06:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 40334385DC1A Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-345-z0NBxqiIP4ifmjMSi28lUw-1; Sat, 04 Apr 2020 11:06:26 -0400 X-MC-Unique: z0NBxqiIP4ifmjMSi28lUw-1 Received: by mail-qk1-f199.google.com with SMTP id r64so9359798qkc.17 for ; Sat, 04 Apr 2020 08:06:26 -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:subject:date:message-id; bh=mi3zbc5cA79WymSf6tNTdwnNts1Ph1uu/8nepIffPt4=; b=cQ+Rz6mSk9pas8PF5u5tdVypI//PZmQJ3VZpEn3RdfsvEi3iIvPAWo1l7TrUTtAaBy XKQQKp/lSdPfa3jtfVJqX9bHT/PCo6TJlcpAIK7RecLaxUhS4cRQrX5T8NsCve/SbjDz HuMn3B+7Mav2CDht4fToNruLADs2Xv4+VRKYvMDku3qHWl2D4PrcrIYK7uSS9XctfOoI szYfrORV0/+AIQURbfp1coiURFE/lveyzVtt670Qg1i/SECQr/IeYZK9JCbJuE/udtWC V6VQh6xQ1kXNnmzZXxn2+CJfVdEJtERD2g2Xs40u1Go7YI2N6HIcNDwEIJtJJvXH/YDD UrnQ== X-Gm-Message-State: AGi0PuYhW6m8Vz1ItqDdUX+gWL0G4PDH+v1gB73emSvrnSxMXNDXCdir b+RV+U1qMhdtZQWrq6fVSI25wYviPjdUan/GZLZaJc7inwn/OAMwwzThZKu9un4QDEiOm4Ih6K1 msaCt2QmWzzrCkTyUhg== X-Received: by 2002:ac8:184f:: with SMTP id n15mr12974994qtk.371.1586012785511; Sat, 04 Apr 2020 08:06:25 -0700 (PDT) X-Google-Smtp-Source: APiQypJ7gfZ3naBSvl4oaV8yWG75CaQhPqrC1iACFAjpGOCaWAusHwaXFPbzMUmOgCSt2oTGWYbGUQ== X-Received: by 2002:ac8:184f:: with SMTP id n15mr12974961qtk.371.1586012785147; Sat, 04 Apr 2020 08:06:25 -0700 (PDT) Received: from barrymore.redhat.com (209-6-216-142.s141.c3-0.smr-cbr1.sbo-smr.ma.cable.rcncustomer.com. [209.6.216.142]) by smtp.gmail.com with ESMTPSA id m5sm8009465qtk.85.2020.04.04.08.06.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 Apr 2020 08:06:24 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [pushed] c++: Fix invalid pointer-to-member in requires [PR67825] Date: Sat, 4 Apr 2020 11:06:23 -0400 Message-Id: <20200404150623.7963-1-jason@redhat.com> X-Mailer: git-send-email 2.18.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-29.9 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, 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: Jason Merrill via Gcc-patches From: "Li, Pan2 via Gcc-patches" Reply-To: Jason Merrill Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" A recent change to cmcstl2 led to two tests failing due to this bug: our valid expression checking in the context of a requires-expression wasn't catching that an expression of member function type can only appear as the function operand of a call expression. Fixed by using convert_to_void to do the same checking as a discarded-value expression. This patch also fixes 67825, which already had a testcase, but the testcase was testing for the wrong behavior. Tested x86_64-pc-linux-gnu, applying to trunk. gcc/cp/ChangeLog 2020-04-04 Jason Merrill PR c++/67825 * constraint.cc (tsubst_valid_expression_requirement): Call convert_to_void. --- gcc/cp/constraint.cc | 5 ++++- gcc/testsuite/g++.dg/cpp2a/concepts-pmf1.C | 22 +++++++++++++++++++ gcc/testsuite/g++.dg/cpp2a/concepts-pr67825.C | 2 +- 3 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp2a/concepts-pmf1.C base-commit: bab8d9625f4cdeaf9bb45e28ab62abe47c3827f9 diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index 9c21ce80256..e5308414879 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -1864,7 +1864,10 @@ hash_placeholder_constraint (tree c) static tree tsubst_valid_expression_requirement (tree t, tree args, subst_info info) { - return tsubst_expr (t, args, info.complain, info.in_decl, false); + tree r = tsubst_expr (t, args, info.complain, info.in_decl, false); + if (convert_to_void (r, ICV_STATEMENT, info.complain) == error_mark_node) + return error_mark_node; + return r; } diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-pmf1.C b/gcc/testsuite/g++.dg/cpp2a/concepts-pmf1.C new file mode 100644 index 00000000000..30d2b2d4a48 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-pmf1.C @@ -0,0 +1,22 @@ +// Make sure that the requirement fails because a .* expression of function +// type can only be used in a call. + +// { dg-do compile { target concepts } } + +template +constexpr decltype(auto) invoke(D (T::*pmd), T&& t) + noexcept(noexcept(t.*pmd)) + requires requires { t.*pmd; } + { return t.*pmd; } + +char invoke(...); + +struct A +{ + int f(); +}; + +int main() +{ + static_assert(sizeof(invoke (&A::f, A())) == 1); +} diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-pr67825.C b/gcc/testsuite/g++.dg/cpp2a/concepts-pr67825.C index 95698e99978..fff414b8eb2 100644 --- a/gcc/testsuite/g++.dg/cpp2a/concepts-pr67825.C +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-pr67825.C @@ -15,6 +15,6 @@ template concept bool C() { } int main() { - static_assert(C()); + static_assert(!C()); return 0; }