re PR c++/8570 (line number in error message is badly placed with illegal…

re PR c++/8570 (line number in error message is badly placed with illegal template friend declaration)

2007-11-12  Manuel Lopez-Ibanez  <manu@gcc.gnu.org>

	PR c++/8570
cp/
	* pt.c (redeclare_class_template): Update error message. Use a
	note to show the previous declaration.
	(tsubst_friend_class): Use the location of the friend template as
	the input location before calling redeclare_class_template.
testsuite/
	* g++.old-deja/g++.ns/template13.C: Update expected output.
	* g++.old-deja/g++.pt/friend23.C: Likewise.
	* g++.dg/warn/pr8570.C: New.

From-SVN: r130092
parent acd7ad0a
2007-11-12 Manuel Lopez-Ibanez <manu@gcc.gnu.org>
PR c++/8570
* pt.c (redeclare_class_template): Update error message. Use a
note to show the previous declaration.
(tsubst_friend_class): Use the location of the friend template as
the input location before calling redeclare_class_template.
2007-11-11 Jakub Jelinek <jakub@redhat.com> 2007-11-11 Jakub Jelinek <jakub@redhat.com>
PR c++/34068 PR c++/34068
......
...@@ -4151,10 +4151,10 @@ redeclare_class_template (tree type, tree parms) ...@@ -4151,10 +4151,10 @@ redeclare_class_template (tree type, tree parms)
if (TREE_VEC_LENGTH (parms) != TREE_VEC_LENGTH (tmpl_parms)) if (TREE_VEC_LENGTH (parms) != TREE_VEC_LENGTH (tmpl_parms))
{ {
error ("previous declaration %q+D", tmpl); error ("redeclared with %d template parameter(s)",
error ("used %d template parameter(s) instead of %d", TREE_VEC_LENGTH (parms));
TREE_VEC_LENGTH (tmpl_parms), inform ("previous declaration %q+D used %d template parameter(s)",
TREE_VEC_LENGTH (parms)); tmpl, TREE_VEC_LENGTH (tmpl_parms));
return false; return false;
} }
...@@ -4193,7 +4193,7 @@ redeclare_class_template (tree type, tree parms) ...@@ -4193,7 +4193,7 @@ redeclare_class_template (tree type, tree parms)
A template-parameter may not be given default arguments A template-parameter may not be given default arguments
by two different declarations in the same scope. */ by two different declarations in the same scope. */
error ("redefinition of default argument for %q#D", parm); error ("redefinition of default argument for %q#D", parm);
error ("%J original definition appeared here", tmpl_parm); inform ("%Joriginal definition appeared here", tmpl_parm);
return false; return false;
} }
...@@ -6521,9 +6521,15 @@ tsubst_friend_class (tree friend_tmpl, tree args) ...@@ -6521,9 +6521,15 @@ tsubst_friend_class (tree friend_tmpl, tree args)
> TMPL_ARGS_DEPTH (args)) > TMPL_ARGS_DEPTH (args))
{ {
tree parms; tree parms;
location_t saved_input_location;
parms = tsubst_template_parms (DECL_TEMPLATE_PARMS (friend_tmpl), parms = tsubst_template_parms (DECL_TEMPLATE_PARMS (friend_tmpl),
args, tf_warning_or_error); args, tf_warning_or_error);
saved_input_location = input_location;
input_location = DECL_SOURCE_LOCATION (friend_tmpl);
redeclare_class_template (TREE_TYPE (tmpl), parms); redeclare_class_template (TREE_TYPE (tmpl), parms);
input_location = saved_input_location;
} }
friend_type = TREE_TYPE (tmpl); friend_type = TREE_TYPE (tmpl);
......
2007-11-12 Manuel Lopez-Ibanez <manu@gcc.gnu.org>
PR c++/8570
* g++.old-deja/g++.ns/template13.C: Update expected output.
* g++.old-deja/g++.pt/friend23.C: Likewise.
* g++.dg/warn/pr8570.C: New.
2007-11-11 Jakub Jelinek <jakub@redhat.com> 2007-11-11 Jakub Jelinek <jakub@redhat.com>
PR c++/34068 PR c++/34068
// PR c++/8570
// { dg-do compile }
// { dg-options "" }
template <typename T, typename P>
class X { // { dg-warning "note: previous declaration .* used 2" }
public:
X() { }
private:
template <typename U> friend class X; // { dg-error "error: .*redeclared with 1 template parameter" }
};
X<int, int> i;
...@@ -5,7 +5,7 @@ namespace bar ...@@ -5,7 +5,7 @@ namespace bar
// trick it to provide some prior declaration // trick it to provide some prior declaration
template<class T> template<class T>
void foo(); // { dg-error "definition" } void foo(); // { dg-error "definition" }
template<class T>class X; // { dg-error "previous declaration" } template<class T>class X; // { dg-error "note: previous declaration" }
} }
template <typename T> template <typename T>
...@@ -20,4 +20,4 @@ template<> void bar::foo<int>() // { dg-error "different namespace" } ...@@ -20,4 +20,4 @@ template<> void bar::foo<int>() // { dg-error "different namespace" }
} }
template<class T,class U> template<class T,class U>
class bar::X{}; // { dg-error "1 template parameter" } class bar::X{}; // { dg-error "error: redeclared with 2 template parameter" }
// { dg-do assemble } // { dg-do assemble }
template <class T = int> // { dg-error "" } original definition template <class T = int> // { dg-error "note: original definition" }
struct S struct S
{ // { dg-error "" } redefinition of default arg {
template <class U = int> template <class U = int>
friend class S; friend class S; // { dg-error "redefinition of default argument" }
}; };
template struct S<int>; template struct S<int>;
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