* Patch for g++ template bug
@ 1997-08-24 4:21 Mark Mitchell
0 siblings, 0 replies; only message in thread
From: Mark Mitchell @ 1997-08-24 4:21 UTC (permalink / raw)
To: egcs
Enclosed is a bug description and patch for a g++ template bug.
Please let me know if there is anything I can do to help get this
patch installed.
--
Mark Mitchell mmitchell@usa.net
Stanford University http://www.stanford.edu
Description
-----------
g++ emits an incorrect error message on a valid use of templates, and
therefore produces no object code. Enclosed below is the error message and
the source file:
supernova% g++ -v
Reading specs from /home/mitchell/egcs/lib/gcc-lib/i686-pc-linux-gnulibc1/egcs-2.90.01/specs
gcc version egcs-2.90.01 970821 (gcc2-970802 experimental)
supernova% g++ -c test.cpp
test.cpp:18: new declaration `struct A<U *> B<U>::foo()'
test.cpp:13: ambiguates old declaration `struct A<U *> B<U>::foo()'
test.cpp
--------
template <class T>
struct A
{
A(T t);
};
template <class U>
struct B
{
typedef A<U*> a;
A<const U*> foo();
};
template <class U>
A<const U*> B<U>::foo()
{
}
void f()
{
B<char> b;
b.foo();
}
Note that the error message mentions A<U *> when in fact A<const U*>
is the appropriate type. This is only a bug in the type_as_string()
function; the type is actually "const U" judging by the
TREE_READONLY() bit. In addition, since the declarations are
identical, there should be no ambiguity.
Fix
---
Below is the marvelously simple fix, does not merely correct the error
message, but in fact makes it go away completely!
Index: cp/ChangeLog
===================================================================
RCS file: /home/mitchell/Repository/egcs/cp/ChangeLog,v
retrieving revision 1.1.1.2
diff -c -r1.1.1.2 ChangeLog
*** ChangeLog 1997/08/22 06:35:53 1.1.1.2
--- ChangeLog 1997/08/24 01:04:44
***************
*** 1,3 ****
--- 1,8 ----
+ Sat Aug 23 18:02:59 1997 Mark Mitchell <mmitchell@usa.net>
+
+ * error.c (type_as_string): Put const/volatile on template type
+ parameters where appropriate.
+
Thu Aug 21 18:48:44 1997 Jason Merrill <jason@yorick.cygnus.com>
* lex.c (real_yylex): Refer to __complex instead of complex.
Index: cp/error.c
===================================================================
RCS file: /home/mitchell/Repository/egcs/cp/error.c,v
retrieving revision 1.1.1.2
diff -c -r1.1.1.2 error.c
*** error.c 1997/08/22 06:35:58 1.1.1.2
--- error.c 1997/08/24 01:05:02
***************
*** 230,235 ****
--- 230,236 ----
break;
case TEMPLATE_TYPE_PARM:
+ dump_readonly_or_volatile (t, after);
if (TYPE_IDENTIFIER (t))
OB_PUTID (TYPE_IDENTIFIER (t));
else
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~1997-08-24 4:21 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-08-24 4:21 Patch for g++ template bug Mark Mitchell
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).