From patchwork Mon May 11 22:43:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 1288106 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=Ft6bZVjq; 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 49LbZD4Zr4z9sRf for ; Tue, 12 May 2020 08:43:30 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1B1D9386F023; Mon, 11 May 2020 22:43:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1B1D9386F023 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1589237007; bh=4fOu67fDkaZ5C71n2wr8sIBMvO/NCrjpkkFJGW7wXuc=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=Ft6bZVjq5s/lHMLYFLjoSq1DXpTCAM87y3MraX9JXulpVcIrfwwO5SMCsmZFm7aqF 8DSuYV/AaAd1QVHQ39boo4y7zBAvGtNAZrGH4QwTmoLQztHPF8uhCSWkwhoVYkSNgJ wdIGKbHbxwR7BbEZrAavTb28t6BSRQ7Za26nqFLU= 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-2.mimecast.com [205.139.110.61]) by sourceware.org (Postfix) with ESMTP id 7E4763851C07 for ; Mon, 11 May 2020 22:43:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 7E4763851C07 Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-184-bCPyxQd5O-KNXpPkqiQ2Ew-1; Mon, 11 May 2020 18:43:22 -0400 X-MC-Unique: bCPyxQd5O-KNXpPkqiQ2Ew-1 Received: by mail-qv1-f71.google.com with SMTP id dh14so11142198qvb.4 for ; Mon, 11 May 2020 15:43:22 -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=4fOu67fDkaZ5C71n2wr8sIBMvO/NCrjpkkFJGW7wXuc=; b=cUlupssWQqLSW28mPPkQppPgL8GAWe0QLuv33tcj1VgBUeW2vdGSolcdyZ1oMQY8+B 2WpWMFI8IajCLYh9zMy7kzhguamVqkb8DPkYDob0jrFP5U/GDGCpZ37QAYOlsJdyMxje 6xL3bx35e0FPVGbGF8+g7vpl+5/u5dAcuGLxIZsnjpeB9vAW5OBp3SeDSsDanaAAfSxi 4unGt/z/z6Je2KVaBqUlxlNpb3EuT6uq6d7QxCbYPLpGs8hPz62BZEbKK0BXPNlfsTWp eagyy0ArsTeeTWEkt6WPe6xJwtFBgSlwh4ipuUt40n1reoISBHmpv4aPxoJ5S1VkoDeB wJIg== X-Gm-Message-State: AGi0PuYYnlzaBENEVEbZdSkd8Zvj+iXavLK311NkruVqrZxLlbQjxj9Z jD6Dtkv180IVM4ds+ziBmqjZ7/tnLKy1OxxveRRD2RY9D1mnEegAQbicXLdWnvqhhdDdiyyrvLL GAveZsS3DsExWJRlHHA== X-Received: by 2002:aed:3009:: with SMTP id 9mr19078155qte.191.1589237001642; Mon, 11 May 2020 15:43:21 -0700 (PDT) X-Google-Smtp-Source: APiQypKJq2FbOutIAZUD8517pxIFo9qQWo8dG2zf8eWWNTzKsi9y3uMbgBK22tbtlbx4iQACCY+0Sw== X-Received: by 2002:aed:3009:: with SMTP id 9mr19078134qte.191.1589237001401; Mon, 11 May 2020 15:43:21 -0700 (PDT) Received: from localhost.localdomain (ool-457d493a.dyn.optonline.net. [69.125.73.58]) by smtp.gmail.com with ESMTPSA id u56sm2195145qtb.91.2020.05.11.15.43.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 May 2020 15:43:20 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [PATCH] c++: premature requires-expression folding [PR95020] Date: Mon, 11 May 2020 18:43:18 -0400 Message-Id: <20200511224318.994420-1-ppalka@redhat.com> X-Mailer: git-send-email 2.26.2.561.g07d8ea56f2 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-19.7 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_H2, 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" In the testcase below we're prematurely folding away the requires-expression to 'true' after substituting in the function's template arguments, but before substituting in the lambda's deduced template arguments. This happens because during the first tsubst_requires_expr, processing_template_decl is 1 but 'args' is just {void} and therefore non-dependent, so we end up folding away the requires-expression to boolean_true_node before we could substitute in the lambda's template arguments and determine that '*v' is ill-formed. This patch removes the uses_template_parms check when deciding in tsubst_requires_expr whether to keep around a new requires-expression. Regardless of whether the template arguments are dependent, there still might be more template parameters to later substitute in -- as in the testcase below -- and even if not, tsubst_expr doesn't perform full semantic processing unless !processing_template_decl, so it seems we should wait until then to fold away the requires-expression. Passes 'make check-c++', does this look OK to commit after a full bootstrap/regtest? gcc/cp/ChangeLog: PR c++/95020 * constraint.c (tsubst_requires_expr): Produce a new requires-expression when processing_template_decl, even if template arguments are not dependent. gcc/testsuite/ChangeLog: PR c++/95020 * g++/cpp2a/concepts-lambda7.C: New test. --- gcc/cp/constraint.cc | 4 +--- gcc/testsuite/g++.dg/cpp2a/concepts-lambda7.C | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp2a/concepts-lambda7.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index 4ad17f3b7d8..8ee347cae60 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -2173,9 +2173,7 @@ tsubst_requires_expr (tree t, tree args, if (reqs == error_mark_node) return boolean_false_node; - /* In certain cases, produce a new requires-expression. - Otherwise the value of the expression is true. */ - if (processing_template_decl && uses_template_parms (args)) + if (processing_template_decl) return finish_requires_expr (cp_expr_location (t), parms, reqs); return boolean_true_node; diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-lambda7.C b/gcc/testsuite/g++.dg/cpp2a/concepts-lambda7.C new file mode 100644 index 00000000000..50746b777a3 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-lambda7.C @@ -0,0 +1,14 @@ +// PR c++/95020 +// { dg-do compile { target c++2a } } + +template +void foo() { + auto t = [](auto v) { + static_assert(requires { *v; }); // { dg-error "static assertion failed" } + }; + t(0); +} + +void bar() { + foo(); +}