This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: template expansion bug or correct behaviour?
- To: egcs-bugs at cygnus dot com
- Subject: Re: template expansion bug or correct behaviour?
- From: Dave MacDonald <davidm at idirect dot com>
- Date: Mon, 08 Dec 1997 20:57:31 -0500
I guess I wasn't clear in a previous message, so I'll start again...
I've tried compiling the PRCS configuration mgmt package using
egcs-971201, but it produces an error that I've been able to reproduce
with the following program (the #define SHOWERROR distinguishes between
a compilable and non-compilable version):
template <class Key, class Data>
class HashTable {
public:
#ifdef SHOWERROR
HashTable(int (*func0)(const Key&, int),
bool (*equal0)(const Key&, const Key&)){};
#else
HashTable(int (*func0)(Key&, int),
bool (*equal0)(Key&, Key&)){};
#endif
~HashTable(){};
};
int pathname_hash(const char*&, int)
{
return 0;
}
bool pathname_equal(const char*&, const char*&)
{
return true;
}
main(int, char**)
{
HashTable<const char*, int> descriptors(pathname_hash,
pathname_equal);
}
For example:
~/tst# c++ --version
egcs-2.90.20 971201 (gcc2-970802 experimental)
~/tst# c++ -DSHOWERROR projdesc.cc
projdesc.cc: In function `int main(int, char **)':
projdesc.cc:26: no matching function for call to `HashTable<const char
*,int>::HashTable (int ()(const char *&, int), bool ()(const char *&,
const char *&))'
projdesc.cc:26: candidates are: HashTable<const char
*,int>::HashTable(const HashTable<const char *,int> &)
projdesc.cc:6: HashTable<const char
*,int>::HashTable(int (*)(const char *const &, int), bool (*)(const char
*const &, const char *const &))
However, if I compile without the preprocessor symbol SHOWERROR, (e.g.
"c++ projdesc.cc"), it compiles without complaint. That is, if I remove
the "const" modifiers from the paramaterized types in the constructor
definition, everything is OK.
I'm running Linux 2.0.28 with gnulibc1 on a Pentium-133.
I've compiled PRCS on Solaris, HP-UX and AIX using the native platform
C++ compilers, and I get no complaint where egcs chokes. I've also used
gcc 2.7.2.2 to successfully compile PRCS.
My question relates to how egcs expanded the template instantiation
HashTable<const char *, int>
The error message indicates that egcs expanded the class's constructor
from
HashTable(int (*func0)(const Key&, int),
bool (*equal0)(const Key&, const Key&)){};
into
HashTable(int (*func0)(const char * const&, int),
bool (*equal0)(const char * const &, const char * const&)){};
A simplistic expansion of the template would give
HashTable(int (*func0)(const const char *, int),
bool (*equal0)(const const char *&, const const char *&)){};
which looks wrong, but I don't know how the standard says this should be
expanded.
Other compilers and previous gcc's either expand it differently or
recognize "const char *&" as being the same as "const char * const&". So
the real question is:
Is it a bug in how egcs expanded the template instantiation, or is PRCS
depending upon an old/incorrect implementation of C++?
Sorry this is so long, but I wanted to make sure I got my point across
this time.
-Dave.