From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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) From: Jason Merrill 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 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable 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-List-Received-Date: Sat, 04 Apr 2020 15:06:33 -0000 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 d= o 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 =09PR c++/67825 =09* constraint.cc (tsubst_valid_expression_requirement): Call =09convert_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 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 =3D tsubst_expr (t, args, info.complain, info.in_decl, false); + if (convert_to_void (r, ICV_STATEMENT, info.complain) =3D=3D error_mark_= node) + return error_mark_node; + return r; } =20 =20 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 functio= n +// 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())) =3D=3D 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() { } =20 int main() { - static_assert(C()); + static_assert(!C()); return 0; } base-commit: bab8d9625f4cdeaf9bb45e28ab62abe47c3827f9 --=20 2.18.1