public inbox for libstdc++-cvs@sourceware.org
help / color / mirror / Atom feed
From: Alexandre Oliva <aoliva@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org
Subject: [gcc(refs/users/aoliva/heads/testme)] c++: Explain fn template argument type/value mismatches [PR66439]
Date: Tue, 26 May 2020 04:31:46 +0000 (GMT)	[thread overview]
Message-ID: <20200526043146.401143896C2B@sourceware.org> (raw)

https://gcc.gnu.org/g:864fed4a491606a7b17325d847e1d723d2a44104

commit 864fed4a491606a7b17325d847e1d723d2a44104
Author: Patrick Palka <ppalka@redhat.com>
Date:   Mon May 18 23:50:14 2020 -0400

    c++: Explain fn template argument type/value mismatches [PR66439]
    
    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.
    
    gcc/cp/ChangeLog:
    
            PR c++/66439
            * pt.c (fn_type_unification): Pass 'fn' instead of NULL_TREE as
            the 'in_decl' parameter to coerce_template_parms.
    
    gcc/testsuite/ChangeLog:
    
            PR c++/66439
            * 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:
    
            PR c++/66439
            * testsuite/20_util/pair/astuple/get_neg.cc: Prune "type/value
            mismatch" messages.
            * testsuite/20_util/tuple/element_access/get_neg.cc: Likewise.

Diff:
---
 gcc/cp/ChangeLog                                              |  6 ++++++
 gcc/cp/pt.c                                                   |  2 +-
 gcc/testsuite/ChangeLog                                       |  9 +++++++++
 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 +++++++++++
 libstdc++-v3/ChangeLog                                        |  7 +++++++
 libstdc++-v3/testsuite/20_util/pair/astuple/get_neg.cc        |  1 +
 .../testsuite/20_util/tuple/element_access/get_neg.cc         |  1 +
 10 files changed, 43 insertions(+), 2 deletions(-)

diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 4e446585aa4..cd81891201d 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,9 @@
+2020-05-19  Patrick Palka  <ppalka@redhat.com>
+
+	PR c++/66439
+	* pt.c (fn_type_unification): Pass 'fn' instead of NULL_TREE as
+	the 'in_decl' parameter to coerce_template_parms.
+
 2020-05-18  Marek Polacek  <polacek@redhat.com>
 
 	PR c++/94955
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index cad5b217f3c..50933cbc23b 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -20989,7 +20989,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/ChangeLog b/gcc/testsuite/ChangeLog
index 02de8028552..b0315b0207b 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,12 @@
+2020-05-19  Patrick Palka  <ppalka@redhat.com>
+
+	PR c++/66439
+	* 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.
+
 2020-05-18  Marek Polacek  <polacek@redhat.com>
 
 	PR c++/94955
diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-ts4.C b/gcc/testsuite/g++.dg/cpp2a/concepts-ts4.C
index 23ed929acf4..cc49ff4fb27 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<int>(); // { 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 597ad5e1ae1..8aede575f75 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<X>();
   f<int>(); // { 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<int> s2a;
   S2<char, signed char, unsigned char> s2b;
@@ -69,4 +71,4 @@ void driver2()
   S6<void, void> s6a;
   S6<void, int> s6c; // { dg-error "template constraint failure" }
   S6<void, void, void> 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<int N> struct S { };
+
+template<template<typename> class TT>
+void foo();
+
+void bar()
+{
+  foo<S>(); // { dg-error "no matching function" }
+  // { dg-error "type/value mismatch at argument 1" "" { target *-*-* } .-1 }
+  // { dg-message "expected a template of type .template<class> class TT., got .template<int N> struct S." "" { target *-*-* } .-2 }
+}
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index dde62ad4779..ae1ec87589c 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,3 +1,10 @@
+2020-05-19  Patrick Palka  <ppalka@redhat.com>
+
+	PR c++/66439
+	* testsuite/20_util/pair/astuple/get_neg.cc: Prune "type/value
+	mismatch" messages.
+	* testsuite/20_util/tuple/element_access/get_neg.cc: Likewise.
+
 2020-05-15  H.J. Lu  <hongjiu.lu@intel.com>
 
 	PR bootstrap/95147
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" }


                 reply	other threads:[~2020-05-26  4:31 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200526043146.401143896C2B@sourceware.org \
    --to=aoliva@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    --cc=libstdc++-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).