This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Problems with -fno-implicit-templates (problem 1)
- To: egcs-bugs at cygnus dot com
- Subject: Problems with -fno-implicit-templates (problem 1)
- From: Carlo Wood <carlo at runaway dot xs4all dot nl>
- Date: Sat, 8 Aug 1998 03:31:40 +0200 (CEST)
Hi, I sent this to the egcs list before, but I suppose I should
have sent it to the bugs list.
Consider the following small code snippet:
---------------foo.cc---------------------
class dstream { };
template <class TYPE>
dstream &operator<<(dstream &o, const TYPE &data) { return o; }
dstream& operator<<(dstream& o, const char *data) { return o; }
int main(void)
{
dstream d;
d << "a string constant";
}
------------------------------------------
This compiles fine with:
>g++ foo.cc
>nm -C a.out | grep operator
08048560 T operator<<(dstream &, char const *)
080485d0 W dstream & operator<<<char ()[17]>(dstream &, char ()[17] const &)
But it incorrectly(?) uses the template, and not the specialisation.
This becomes apparent with:
>g++ -fno-implicit-templates foo.cc
/tmp/cceZqrVa.o: In function `main':
/tmp/cceZqrVa.o(.text+0x24): undefined reference to `dstream & operator<<<char ()[17]>(dstream &, char ()[17] const &)'
collect2: ld returned 1 exit status
Note that adding -Wwrite-strings (which should never change the code imho)
causes this to work:
>g++ -fno-implicit-templates -Wwrite-strings foo.cc
>nm -C a.out | grep operator
08048560 T operator<<(dstream &, char const *)
Apart from the fact that if we assume that WITHOUT -Wwrite-strings
we do not only not WARN when we write to a string, but we even make
it explicitly of type 'char [17]' (which is a bug I think; it should
still be 'const char [17]', even while it does not produce a warning/error
when converted to 'char *'), then shouldn't still the specialisation
be called - and not the template? I tried to understand the standard
at this point, but chapter 13 is way over my head :/
Note Alexandre Oliva response to my post to egcs:
http://www.cygnus.com/ml/egcs/1998-Aug/0162.html and
http://www.cygnus.com/ml/egcs/1998-Aug/0152.html
--
Carlo Wood <carlo@runaway.xs4all.nl>