From patchwork Tue Apr 28 13:48:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 1278504 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=X5IfjmpS; 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 49BNK92L9Lz9sP7 for ; Tue, 28 Apr 2020 23:48:43 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 019333851C12; Tue, 28 Apr 2020 13:48:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 019333851C12 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1588081721; bh=6Qywuth9lnsrM9y/zXe8P4UP+0kq2Gm/eKy5QWkOqzs=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=X5IfjmpSe6Euxe5NkEM6jLVQ1733QX0S4orsNaO60FfvcE7lLhl2naTjSB9LCiCKq v9ewSAyC7z+/28h5vyLnMIRh2MOKDXGjgzt5UwGPrwHYGWoCuaIpJmzsRt9IoZLuA8 qgAisXz7o5q0/pZRuVvIau6wGTmsGGf8B8dvRiKY= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) by sourceware.org (Postfix) with ESMTP id CFE74385DC32 for ; Tue, 28 Apr 2020 13:48:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org CFE74385DC32 Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-286-dk6CvH_nMKGL8eOr_rWrsw-1; Tue, 28 Apr 2020 09:48:36 -0400 X-MC-Unique: dk6CvH_nMKGL8eOr_rWrsw-1 Received: by mail-qk1-f198.google.com with SMTP id d13so17608219qke.19 for ; Tue, 28 Apr 2020 06:48:36 -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=WqogX0KFKYOLQOVa7dJ8yLRaTC7FasO4tBG3vqNhCLo=; b=e9p0GWSK1BPr40766ycOao1iWScAEp1aBYrH7Ckh1wlTU5CCcDC0ga2h2Q2bbg75Gh HLKzeIR3EXHaED4xOu5i4oU211CzTv86dk1dPj/C9oRmr/3IuZTN+HCeMXRgmju0+7YA 7Q3cFKw0ar1DfQ9Pxh1OUIafn0UXAe7hoJj/Ngmdsfja3npgTpI7RKeBVW5cnZ4ANC9U wkRxPMu+2nWCdoxW20x7MB2NRwVgpl0hSfO81PgR/WCx5rMwTehRhr8V9rP1+yJ5jykH w/Im8Agzx2VGCEnMjqb001oTlNgN30oF5Na+QAUlMNTrNUa15RcDVN9V6/FjI3S5s4HY 27Ug== X-Gm-Message-State: AGi0PuZ366z3KUS7kY+t7TH372IPSExjay6nuhUijdwboDtyiVotKpdK HQaYmQ6pq17vG6+kKlZImyLWvJUQ+uLCLL1VkKEGgW/EI+1eo+5k0zOlfJm0vSdTF80/OL9UitO GWttQCk0TWyr0d5fGsQ== X-Received: by 2002:a05:620a:16db:: with SMTP id a27mr26603853qkn.116.1588081715653; Tue, 28 Apr 2020 06:48:35 -0700 (PDT) X-Google-Smtp-Source: APiQypJLFdyBhHfLk66pA6O4Eppj+5MZFaB+xSG4ypluQOzRzWGPovaktHVeJvGLdHroyVTKc+qBTQ== X-Received: by 2002:a05:620a:16db:: with SMTP id a27mr26603827qkn.116.1588081715341; Tue, 28 Apr 2020 06:48:35 -0700 (PDT) Received: from localhost.localdomain (ool-457d493a.dyn.optonline.net. [69.125.73.58]) by smtp.gmail.com with ESMTPSA id h2sm13474659qkh.91.2020.04.28.06.48.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Apr 2020 06:48:34 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [PATCH] c++: Parameter pack in requires parameter list [PR94808] Date: Tue, 28 Apr 2020 09:48:22 -0400 Message-Id: <20200428134822.3806212-1-ppalka@redhat.com> X-Mailer: git-send-email 2.26.2.266.ge870325ee8 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-28.0 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: Patrick Palka via Gcc-patches From: Patrick Palka Reply-To: Patrick Palka Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" When printing the substituted parameter list of a requires-expression as part of the "in requirements with ..." context line during concepts diagnostics, we weren't considering that substitution into a parameter pack can yield zero or multiple parameters. Since this patch affects only concepts diagnostics, so far I tested with RUNTESTFLAGS="dg.exp=*concepts*" and also verified that we no longer ICE with the unreduced testcase in the PR. Is this OK to commit after a full bootstrap and regtest? gcc/cp/ChangeLog: PR c++/94808 * error.c (print_requires_expression_info): Substitute into and collect all parameters in a vector first before printing them. Handle zero or multiple parameters of an expanded parameter pack. gcc/testsuite/ChangeLog: PR c++/94808 * g++.dg/concepts/diagnostic12.C: New test. --- gcc/cp/error.c | 21 ++++++++++++++------ gcc/testsuite/g++.dg/concepts/diagnostic12.C | 14 +++++++++++++ 2 files changed, 29 insertions(+), 6 deletions(-) create mode 100644 gcc/testsuite/g++.dg/concepts/diagnostic12.C diff --git a/gcc/cp/error.c b/gcc/cp/error.c index 98c163db572..a314412988f 100644 --- a/gcc/cp/error.c +++ b/gcc/cp/error.c @@ -3752,8 +3752,7 @@ print_requires_expression_info (diagnostic_context *context, tree constr, tree a pp_verbatim (context->printer, "in requirements "); tree parms = TREE_OPERAND (expr, 0); - if (parms) - pp_verbatim (context->printer, "with "); + auto_vec substed_parms; while (parms) { tree next = TREE_CHAIN (parms); @@ -3761,15 +3760,25 @@ print_requires_expression_info (diagnostic_context *context, tree constr, tree a TREE_CHAIN (parms) = NULL_TREE; cp_unevaluated u; tree p = tsubst (parms, args, tf_none, NULL_TREE); - pp_verbatim (context->printer, "%q#D", p); + while (p) + { + substed_parms.safe_push (p); + p = TREE_CHAIN (p); + } TREE_CHAIN (parms) = next; - if (next) - pp_separate_with_comma ((cxx_pretty_printer *)context->printer); - parms = next; } + for (unsigned i = 0; i < substed_parms.length (); i++) + { + if (i == 0) + pp_verbatim (context->printer, "with "); + else + pp_separate_with_comma ((cxx_pretty_printer *)context->printer); + pp_verbatim (context->printer, "%q#D", substed_parms[i]); + } + pp_verbatim (context->printer, "\n"); } diff --git a/gcc/testsuite/g++.dg/concepts/diagnostic12.C b/gcc/testsuite/g++.dg/concepts/diagnostic12.C new file mode 100644 index 00000000000..7dd286291f3 --- /dev/null +++ b/gcc/testsuite/g++.dg/concepts/diagnostic12.C @@ -0,0 +1,14 @@ +// PR c++/94808 +// { dg-do compile { target concepts } } + +template + concept c1 = requires (T t, Args... args) { *t; }; +// { dg-message "in requirements with .int t." "" { target *-*-* } .-1 } + +static_assert(c1); // { dg-error "failed" } + +template + concept c2 = requires (T t, Args... args) { *t; }; +// { dg-message "in requirements with .int t., .char args#0., .bool args#1." "" { target *-*-* } .-1 } + +static_assert(c2); // { dg-error "failed" }