From patchwork Thu May 7 16:47:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 1285493 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=eljeo7rD; 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 49Hzsh43YPz9sSd for ; Fri, 8 May 2020 02:47:50 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7ACAA398541B; Thu, 7 May 2020 16:47:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7ACAA398541B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1588870065; bh=N4oOsGK//hrqAOCfw3pRfX1ZQO7LAUURDrt5xpmANVM=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=eljeo7rDJtgjgrwDB7rFgKPDOWXIQp9lCUN9ll+zwPhuBFH/9Lq07teuhEd5nTpyd wUznrl1JRPFKYLAEQLfaWURcfMoFwKryIR5myoeyGq928dPT640MILbEAT28KJ4RGr fOJ4bXqG/iyPzDHfROJZ+32dw6cXk0kdsGGAa5e0= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) by sourceware.org (Postfix) with ESMTP id BDABA396E848 for ; Thu, 7 May 2020 16:47:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org BDABA396E848 Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-507-ESlSpFFjMImmMTl5tnC8HA-1; Thu, 07 May 2020 12:47:41 -0400 X-MC-Unique: ESlSpFFjMImmMTl5tnC8HA-1 Received: by mail-qv1-f70.google.com with SMTP id u5so6404734qvt.12 for ; Thu, 07 May 2020 09:47:41 -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=2D3CU2BFkDRTeI8wCT8fOEMgtNreS/+740Qp6z/cv8I=; b=NxfotQbhojqFYi4l8B3ESs11p0pdwQQcpWbGSflDExt87ce+5pCgfZfzBAao3CLuX6 SMrBw0hs7pAiAMESe6c4109pkLikAGM7omRdh7MiEP6tM0X0xoi9zsj13hc4Ibb2urk8 kRcRFwOPwLEa5DMNCKe79oXOfGX6ift9uqgenMTobrNcqhgZuvw3H+0TJoSE100cZebv oGSxOQ/GlQ0h6km6WG5MXoHKI+opBAAOzJrj2nxiYjB72nyVYp8xPwzmVNapIYNL+RAV 3sP1tC25L5jKstOFz9xIMarWvny8frcVbr4KHqUD1KvMRgA0qE8I9ANgcIjYSaNRBq4h lTRw== X-Gm-Message-State: AGi0PuYBASPKRBLgpFviv6v+5w2PIBgH+Hu58pBK22d/xvOLFvFf88s0 yyg40FCW8/3oU3q4qAWIjB+y18hediw1mCG0F07XarG9wQZpQ0hlKmsc3C3JjI4gTh2h1fqu7to eQMJFn5vtHkaaAfgmDw== X-Received: by 2002:a37:e310:: with SMTP id y16mr16068041qki.275.1588870059758; Thu, 07 May 2020 09:47:39 -0700 (PDT) X-Google-Smtp-Source: APiQypK5JjzAnGjMYPXG/cfWn9OYJJmTcos1D0SQLm2pWncn/6uFoUS0ra0DL9A1ed/kHzjztNk9Pw== X-Received: by 2002:a37:e310:: with SMTP id y16mr16068009qki.275.1588870059447; Thu, 07 May 2020 09:47:39 -0700 (PDT) Received: from localhost.localdomain (ool-457d493a.dyn.optonline.net. [69.125.73.58]) by smtp.gmail.com with ESMTPSA id o94sm4622656qtd.34.2020.05.07.09.47.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 May 2020 09:47:38 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [PATCH] c++: explain fn template argument type/value mismatch failures Date: Thu, 7 May 2020 12:47:36 -0400 Message-Id: <20200507164736.2813809-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=-20.1 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 Cc: libstdc++@gcc.gnu.org Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" In fn_type_unifcation, we are passing NULL_TREE as the 'in_decl' parameter to coerce_template_parms, and this is causing template type/value mismatch error messages to get suppressed regardless of the value of 'complain'. This means that when substitution into a function template fails due to a type/value mismatch between a template parameter and the provided template argument, we just say "template argument deduction/substitution failed:" without a followup explanation of the failure. Fix this by passing 'fn' instead of NULL_TREE to coerce_template_parms. Passes 'make check-c++', does this look OK to commit after a full bootstrap and regtest? gcc/cp/ChangeLog: * pt.c (fn_type_unification): Pass 'fn' instead of NULL_TREE as the 'in_decl' parameter to coerce_template_parms. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/concepts-ts4.C: Expect a "type/value mismatch" diagnostic. * g++.dg/cpp2a/concepts-ts6.C: Likewise. * g++.dg/template/error56.C: Likewise. * g++.dg/template/error59.C: New test. libstdc++-v3/ChangeLog: * testsuite/20_util/pair/astuple/get_neg.cc: Prune "type/value mismatch" messages. * testsuite/20_util/tuple/element_access/get_neg.cc: Likewise. --- gcc/cp/pt.c | 2 +- gcc/testsuite/g++.dg/cpp2a/concepts-ts4.C | 2 ++ gcc/testsuite/g++.dg/cpp2a/concepts-ts6.C | 4 +++- gcc/testsuite/g++.dg/template/error56.C | 2 ++ gcc/testsuite/g++.dg/template/error59.C | 11 +++++++++++ .../testsuite/20_util/pair/astuple/get_neg.cc | 1 + .../testsuite/20_util/tuple/element_access/get_neg.cc | 1 + 7 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/template/error59.C diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index c6091127225..52bb6f34d6a 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -21088,7 +21088,7 @@ fn_type_unification (tree fn, /* Adjust any explicit template arguments before entering the substitution context. */ explicit_targs - = (coerce_template_parms (tparms, explicit_targs, NULL_TREE, + = (coerce_template_parms (tparms, explicit_targs, fn, complain|tf_partial, /*require_all_args=*/false, /*use_default_args=*/false)); diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-ts4.C b/gcc/testsuite/g++.dg/cpp2a/concepts-ts4.C index aa96621d9cf..2b0fd1b8deb 100644 --- a/gcc/testsuite/g++.dg/cpp2a/concepts-ts4.C +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-ts4.C @@ -31,4 +31,6 @@ void driver() fn<0>(); // OK fn<-1>(); // { dg-error "" } fn(); // { dg-error "no matching function" } + // { dg-error "type/value mismatch at argument 1" "" { target *-*-* } .-1 } + // { dg-message "expected a constant of type .int., got .int." "" { target *-*-* } .-2 } } diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-ts6.C b/gcc/testsuite/g++.dg/cpp2a/concepts-ts6.C index bf665aa6308..e3dff54c83d 100644 --- a/gcc/testsuite/g++.dg/cpp2a/concepts-ts6.C +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-ts6.C @@ -25,6 +25,8 @@ void driver1() { f(); f(); // { dg-error "no matching function for call" } + // { dg-error "type/value mismatch at argument 1" "" { target *-*-* } .-1 } + // { dg-message "expected a class template, got .int." "" { target *-*-* } .-2 } S2 s2a; S2 s2b; @@ -69,4 +71,4 @@ void driver2() S6 s6a; S6 s6c; // { dg-error "template constraint failure" } S6 s6b; // { dg-error "wrong number of template arguments" } -} \ No newline at end of file +} diff --git a/gcc/testsuite/g++.dg/template/error56.C b/gcc/testsuite/g++.dg/template/error56.C index 3eda04c3225..e85471a50b0 100644 --- a/gcc/testsuite/g++.dg/template/error56.C +++ b/gcc/testsuite/g++.dg/template/error56.C @@ -9,4 +9,6 @@ struct A int main() { A().f<1>(); // { dg-error "f<1>" } + // { dg-error "type/value mismatch at argument 1" "" { target *-*-* } .-1 } + // { dg-message "expected a type, got .1." "" { target *-*-* } .-2 } } diff --git a/gcc/testsuite/g++.dg/template/error59.C b/gcc/testsuite/g++.dg/template/error59.C new file mode 100644 index 00000000000..f81a28c2f1a --- /dev/null +++ b/gcc/testsuite/g++.dg/template/error59.C @@ -0,0 +1,11 @@ +template struct S { }; + +template class TT> +void foo(); + +void bar() +{ + foo(); // { dg-error "no matching function" } + // { dg-error "type/value mismatch at argument 1" "" { target *-*-* } .-1 } + // { dg-message "expected a template of type .template class TT., got .template struct S." "" { target *-*-* } .-2 } +} diff --git a/libstdc++-v3/testsuite/20_util/pair/astuple/get_neg.cc b/libstdc++-v3/testsuite/20_util/pair/astuple/get_neg.cc index bcf3940e16d..1f76aef6d73 100644 --- a/libstdc++-v3/testsuite/20_util/pair/astuple/get_neg.cc +++ b/libstdc++-v3/testsuite/20_util/pair/astuple/get_neg.cc @@ -27,3 +27,4 @@ void test01() } // { dg-prune-output "tuple_element<2" } +// { dg-prune-output "type/value mismatch" } diff --git a/libstdc++-v3/testsuite/20_util/tuple/element_access/get_neg.cc b/libstdc++-v3/testsuite/20_util/tuple/element_access/get_neg.cc index 8488e287a98..03ad77215d2 100644 --- a/libstdc++-v3/testsuite/20_util/tuple/element_access/get_neg.cc +++ b/libstdc++-v3/testsuite/20_util/tuple/element_access/get_neg.cc @@ -61,3 +61,4 @@ test03() } // { dg-prune-output "no type named .type" } +// { dg-prune-output "type/value mismatch" }