Bug 8570 - line number in error message is badly placed with illegal template friend declaration
Summary: line number in error message is badly placed with illegal template friend dec...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.2
: P3 normal
Target Milestone: 4.3.0
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
: 12390 13390 (view as bug list)
Depends on:
Blocks:
 
Reported: 2002-11-13 20:56 UTC by Bill Clarke
Modified: 2007-11-12 00:29 UTC (History)
5 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2005-12-11 23:04:03


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Bill Clarke 2002-11-13 20:56:02 UTC
The line number in an error message with illegal is badly placed, nowhere
near the offending friend declaration.

Release:
3.2

Environment:
System: SunOS alto 5.9 Generic sun4u sparc SUNW,Sun-Blade-1000
Architecture: sun4
host: sparc-sun-solaris2.9
build: sparc-sun-solaris2.9
target: sparc-sun-solaris2.9
configured with: ../gcc-3.2/configure --prefix=/space/bill/util --with-cpu=ultrasparc --enable-languages=c,c++,f77

How-To-Repeat:
With this file:
// templ-friend-bug.cc
template <typename T, typename P>
class X {
public:
  X() { }

private:
  template <typename U> friend class X;
};

X<int, int> i;
// end

compiling with g++ 3.2 gives the following message:
? g++ -c templ-friend-bug.cc 
templ-friend-bug.cc: In instantiation of `X<int, int>':
templ-friend-bug.cc:11:   instantiated from here
templ-friend-bug.cc:3: previous declaration `template<class T, class P> class X'
templ-friend-bug.cc:3: used 2 template parameters instead of 1
?

the same occurs with 3.2.1 pre (20021110) and 3.3 pre (20021110)

it would be nice if it mentioned line 8 somewhere in the error message
(presumably the last line).  it took a great deal of time to find the
problem in my code with a rather large template.

my original code also got an ICE in 3.3 pre, but this stripped down version
didn't.  i'll look into that separately.
Comment 1 Wolfgang Bangerth 2002-11-14 07:01:33 UTC
State-Changed-From-To: open->analyzed
State-Changed-Why: Confirmed. I think that this is probably related to PR 2019.
Comment 2 Eric Botcazou 2003-09-08 07:36:29 UTC
Generic C++ front-end problem.
Comment 3 Andrew Pinski 2004-07-26 04:10:17 UTC
*** Bug 12390 has been marked as a duplicate of this bug. ***
Comment 4 Andrew Pinski 2004-07-28 14:45:14 UTC
*** Bug 13390 has been marked as a duplicate of this bug. ***
Comment 5 Manuel López-Ibáñez 2007-11-10 21:28:03 UTC
Still valid in GCC 4.3
Comment 6 Manuel López-Ibáñez 2007-11-12 00:28:54 UTC
Subject: Bug 8570

Author: manu
Date: Mon Nov 12 00:28:41 2007
New Revision: 130092

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=130092
Log:
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.

Added:
    trunk/gcc/testsuite/g++.dg/warn/pr8570.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/pt.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/g++.old-deja/g++.ns/template13.C
    trunk/gcc/testsuite/g++.old-deja/g++.pt/friend23.C

Comment 7 Manuel López-Ibáñez 2007-11-12 00:29:30 UTC
Fixed in GCC 4.3
Comment 8 patchapp@dberlin.org 2007-11-12 05:56:00 UTC
Subject: Bug number PR c++/8570

A patch for this bug has been added to the patch tracker.
The mailing list url for the patch is http://gcc.gnu.org/ml/gcc-patches/2007-11/msg00581.html