From: manu Date: Mon, 12 Nov 2007 00:28:41 +0000 (+0000) Subject: 2007-11-12 Manuel Lopez-Ibanez X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=40db0c7cfeb135c5c9e7727cb20d0cc066574a3f;p=thirdparty%2Fgcc.git 2007-11-12 Manuel Lopez-Ibanez 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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@130092 138bc75d-0d04-0410-961f-82ee72b054a4 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index e41c99028fca..cfeea801148f 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,11 @@ +2007-11-12 Manuel Lopez-Ibanez + + 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 PR c++/34068 diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 4d9f12203444..0339a8c02d3b 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -4151,10 +4151,10 @@ redeclare_class_template (tree type, tree parms) if (TREE_VEC_LENGTH (parms) != TREE_VEC_LENGTH (tmpl_parms)) { - error ("previous declaration %q+D", tmpl); - error ("used %d template parameter(s) instead of %d", - TREE_VEC_LENGTH (tmpl_parms), - TREE_VEC_LENGTH (parms)); + error ("redeclared with %d template parameter(s)", + TREE_VEC_LENGTH (parms)); + inform ("previous declaration %q+D used %d template parameter(s)", + tmpl, TREE_VEC_LENGTH (tmpl_parms)); return false; } @@ -4193,7 +4193,7 @@ redeclare_class_template (tree type, tree parms) A template-parameter may not be given default arguments by two different declarations in the same scope. */ 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; } @@ -6521,9 +6521,15 @@ tsubst_friend_class (tree friend_tmpl, tree args) > TMPL_ARGS_DEPTH (args)) { tree parms; + location_t saved_input_location; parms = tsubst_template_parms (DECL_TEMPLATE_PARMS (friend_tmpl), args, tf_warning_or_error); + + saved_input_location = input_location; + input_location = DECL_SOURCE_LOCATION (friend_tmpl); redeclare_class_template (TREE_TYPE (tmpl), parms); + input_location = saved_input_location; + } friend_type = TREE_TYPE (tmpl); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 78069d25e0b4..3c9a1a098911 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,10 @@ +2007-11-12 Manuel Lopez-Ibanez + + 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 PR c++/34068 diff --git a/gcc/testsuite/g++.dg/warn/pr8570.C b/gcc/testsuite/g++.dg/warn/pr8570.C new file mode 100644 index 000000000000..0136bb1050a0 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/pr8570.C @@ -0,0 +1,13 @@ +// PR c++/8570 +// { dg-do compile } +// { dg-options "" } +template +class X { // { dg-warning "note: previous declaration .* used 2" } +public: + X() { } + +private: + template friend class X; // { dg-error "error: .*redeclared with 1 template parameter" } +}; + +X i; diff --git a/gcc/testsuite/g++.old-deja/g++.ns/template13.C b/gcc/testsuite/g++.old-deja/g++.ns/template13.C index 46555387af3e..7059b1949f85 100644 --- a/gcc/testsuite/g++.old-deja/g++.ns/template13.C +++ b/gcc/testsuite/g++.old-deja/g++.ns/template13.C @@ -5,7 +5,7 @@ namespace bar // trick it to provide some prior declaration template void foo(); // { dg-error "definition" } - templateclass X; // { dg-error "previous declaration" } + templateclass X; // { dg-error "note: previous declaration" } } template @@ -20,4 +20,4 @@ template<> void bar::foo() // { dg-error "different namespace" } } template -class bar::X{}; // { dg-error "1 template parameter" } +class bar::X{}; // { dg-error "error: redeclared with 2 template parameter" } diff --git a/gcc/testsuite/g++.old-deja/g++.pt/friend23.C b/gcc/testsuite/g++.old-deja/g++.pt/friend23.C index abf6c709aba9..baf1a931cbaa 100644 --- a/gcc/testsuite/g++.old-deja/g++.pt/friend23.C +++ b/gcc/testsuite/g++.old-deja/g++.pt/friend23.C @@ -1,10 +1,10 @@ // { dg-do assemble } -template // { dg-error "" } original definition +template // { dg-error "note: original definition" } struct S -{ // { dg-error "" } redefinition of default arg +{ template - friend class S; + friend class S; // { dg-error "redefinition of default argument" } }; template struct S;