Commit a62dbaa4 by Paolo Carlini Committed by Paolo Carlini

re PR c++/54377 (Consider default arguments in "wrong number of template arguments" diagnostic)

/cp
2014-08-14  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/54377
	* pt.c (coerce_template_parms): Improve error message vs default
	arguments.

/testsuite
2014-08-14  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/54377
	* g++.dg/template/pr54377.C: New.
	* g++.dg/cpp0x/pr54377.C: Likewise.
	* g++.dg/cpp0x/alias-decl-2.C: Adjust.
	* g++.dg/cpp0x/pr51226.C: Likewise.
	* g++.dg/cpp0x/variadic2.C: Likewise.
	* g++.dg/parse/too-many-tmpl-args1.C: Likewise.
	* g++.dg/template/dtor3.C: Likewise.
	* g++.dg/template/qualttp4.C: Likewise.
	* g++.dg/template/spec28.C: Likewise.
	* g++.old-deja/g++.brendan/crash8.C: Likewise.
	* g++.old-deja/g++.pt/ttp7.C: Likewise.

From-SVN: r213973
parent 4875c29c
2014-08-14 Paolo Carlini <paolo.carlini@oracle.com> 2014-08-14 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/54377
* pt.c (coerce_template_parms): Improve error message vs default
arguments.
2014-08-14 Paolo Carlini <paolo.carlini@oracle.com>
* parser.c (cp_parser_init_declarator): Remove redundant check of * parser.c (cp_parser_init_declarator): Remove redundant check of
decl_specifiers->type. decl_specifiers->type.
......
...@@ -6861,19 +6861,24 @@ coerce_template_parms (tree parms, ...@@ -6861,19 +6861,24 @@ coerce_template_parms (tree parms,
int variadic_args_p = 0; int variadic_args_p = 0;
int post_variadic_parms = 0; int post_variadic_parms = 0;
/* Likewise for parameters with default arguments. */
int default_p = 0;
if (args == error_mark_node) if (args == error_mark_node)
return error_mark_node; return error_mark_node;
nparms = TREE_VEC_LENGTH (parms); nparms = TREE_VEC_LENGTH (parms);
/* Determine if there are any parameter packs. */ /* Determine if there are any parameter packs or default arguments. */
for (parm_idx = 0; parm_idx < nparms; ++parm_idx) for (parm_idx = 0; parm_idx < nparms; ++parm_idx)
{ {
tree tparm = TREE_VALUE (TREE_VEC_ELT (parms, parm_idx)); tree parm = TREE_VEC_ELT (parms, parm_idx);
if (variadic_p) if (variadic_p)
++post_variadic_parms; ++post_variadic_parms;
if (template_parameter_pack_p (tparm)) if (template_parameter_pack_p (TREE_VALUE (parm)))
++variadic_p; ++variadic_p;
if (TREE_PURPOSE (parm))
++default_p;
} }
inner_args = orig_inner_args = INNERMOST_TEMPLATE_ARGS (args); inner_args = orig_inner_args = INNERMOST_TEMPLATE_ARGS (args);
...@@ -6902,18 +6907,18 @@ coerce_template_parms (tree parms, ...@@ -6902,18 +6907,18 @@ coerce_template_parms (tree parms,
{ {
if (complain & tf_error) if (complain & tf_error)
{ {
if (variadic_p) if (variadic_p || default_p)
{ {
nparms -= variadic_p; nparms -= variadic_p + default_p;
error ("wrong number of template arguments " error ("wrong number of template arguments "
"(%d, should be %d or more)", nargs, nparms); "(%d, should be at least %d)", nargs, nparms);
} }
else else
error ("wrong number of template arguments " error ("wrong number of template arguments "
"(%d, should be %d)", nargs, nparms); "(%d, should be %d)", nargs, nparms);
if (in_decl) if (in_decl)
error ("provided for %q+D", in_decl); inform (input_location, "provided for %q+D", in_decl);
} }
return error_mark_node; return error_mark_node;
......
2014-08-14 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/54377
* g++.dg/template/pr54377.C: New.
* g++.dg/cpp0x/pr54377.C: Likewise.
* g++.dg/cpp0x/alias-decl-2.C: Adjust.
* g++.dg/cpp0x/pr51226.C: Likewise.
* g++.dg/cpp0x/variadic2.C: Likewise.
* g++.dg/parse/too-many-tmpl-args1.C: Likewise.
* g++.dg/template/dtor3.C: Likewise.
* g++.dg/template/qualttp4.C: Likewise.
* g++.dg/template/spec28.C: Likewise.
* g++.old-deja/g++.brendan/crash8.C: Likewise.
* g++.old-deja/g++.pt/ttp7.C: Likewise.
2014-08-14 Tom de Vries <tom@codesourcery.com> 2014-08-14 Tom de Vries <tom@codesourcery.com>
PR rtl-optimization/62004 PR rtl-optimization/62004
......
...@@ -22,7 +22,7 @@ template<class T> using Vec = Vector<T, Alloc<T> >; ...@@ -22,7 +22,7 @@ template<class T> using Vec = Vector<T, Alloc<T> >;
template<class T> void g(Vector<T, Alloc<T> >); template<class T> void g(Vector<T, Alloc<T> >);
template<template<class T> class TT> void h(TT<int>); // { dg-error "provided for" } template<template<class T> class TT> void h(TT<int>); // { dg-message "provided for" }
void void
bar() bar()
......
// PR c++/51226 // PR c++/51226
// { dg-do compile { target c++11 } } // { dg-do compile { target c++11 } }
template<int> struct A // { dg-error "provided" } template<int> struct A // { dg-message "provided" }
{ {
enum E : int; enum E : int;
}; };
......
// PR c++/54377
// { dg-do compile { target c++11 } }
template <typename, typename, typename = void, typename...>
struct foo {}; // { dg-message "provided for" }
foo<int> f; // { dg-error "at least 2" }
...@@ -6,9 +6,9 @@ template<typename... = int> // { dg-error "default argument" } ...@@ -6,9 +6,9 @@ template<typename... = int> // { dg-error "default argument" }
class tuple3; class tuple3;
template<typename T1, typename T2, typename... Rest> template<typename T1, typename T2, typename... Rest>
struct two_or_more {}; // { dg-error "provided for" } struct two_or_more {}; // { dg-message "provided for" }
typedef two_or_more<int> bad; // { dg-error "2 or more" "2 or more" } typedef two_or_more<int> bad; // { dg-error "at least 2" "at least 2" }
void f() void f()
{ {
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Origin: Wolfgang Bangerth <bangerth@ticam.utexas.edu> // Origin: Wolfgang Bangerth <bangerth@ticam.utexas.edu>
// { dg-do compile } // { dg-do compile }
template <typename T> class A // { dg-error "" } template <typename T> class A // { dg-message "" }
{ {
struct B; struct B;
template <typename U> friend typename A<U,void>::B foo(); // { dg-error "" } template <typename U> friend typename A<U,void>::B foo(); // { dg-error "" }
......
// PR c++/19762 // PR c++/19762
template<int> struct A { ~A(){} }; // { dg-error "" } template<int> struct A { ~A(){} }; // { dg-message "provided for" }
template A<>::~A(); // { dg-error "template|declaration" } template A<>::~A(); // { dg-error "template|declaration" }
// PR c++/54377
template <typename, typename, typename = void, typename = void>
struct foo {}; // { dg-message "provided for" }
foo<int> f; // { dg-error "at least 2" }
...@@ -7,7 +7,7 @@ struct A ...@@ -7,7 +7,7 @@ struct A
template <class T> struct B {}; template <class T> struct B {};
}; };
template <template <class, class> class TT> // { dg-error "provided" } template <template <class, class> class TT> // { dg-message "provided for" }
struct X struct X
{ {
TT<int> y; // { dg-error "number" } TT<int> y; // { dg-error "number" }
......
...@@ -2,5 +2,5 @@ ...@@ -2,5 +2,5 @@
// Bad diagnostic // Bad diagnostic
// { dg-do compile } // { dg-do compile }
template<typename> struct A {}; // { dg-error "provided" } template<typename> struct A {}; // { dg-message "provided for" }
template<> struct A<> {}; // { dg-error "wrong number" } template<> struct A<> {}; // { dg-error "wrong number" }
// { dg-do compile } // { dg-do compile }
// GROUPS passed old-abort // GROUPS passed old-abort
template<int a, int b> template<int a, int b>
class Elvis // { dg-error "class Elvis" } class Elvis // { dg-message "class Elvis" }
{ {
} ; } ;
......
...@@ -4,7 +4,7 @@ template<class E> class D ...@@ -4,7 +4,7 @@ template<class E> class D
{ {
}; };
template<template<class> class D,class E> class C // { dg-error "" } ref below template<template<class> class D,class E> class C // { dg-message "" } ref below
{ {
D<int,int> d; // { dg-error "" } arg not match D<int,int> d; // { dg-error "" } arg not match
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment