G++ bug: template c'tors

llewelly@198.dsl.xmission.com llewelly@198.dsl.xmission.com
Sun Dec 19 11:03:00 GMT 1999


On Sun, 19 Dec 1999, Ken Yarnall wrote:

> With this code:
> 
> ----------------gccerr.cpp---------------------
> class Err
> {
> public:
> 
>     template <class FPtr>
>     Err(FPtr f) {}
> };
> 
> class Umm {
> public:
>     Umm(const Err& e)
>         : err(e)
>     {}
> 
>     void doit() {}
> 
> private:
>     Err err;
> };
> 
> void f()
> {}
> 
> int main()
> {
>     Umm u(Err(f));

Allow me to clarify the above line code by removing superflous
  parentheses:

  Umm u(Err f);

Looks like a function decl, doesn't it? Well, that's what the ISO C++
  standard says it is. 'Umm' is the return type. 'u' is the function
  name. 'Err' is type of the first parameter. 'f' is the name of the
  first parameter. The '()' around the f are superflous.

This resolution was considered necessary for backwards compatibility with
  C89.

In other words, this is a bug in the c++ definition, not in g++.

>     u.doit();
>     return 0;
> }
> ----------------gccerr.cpp---------------------
> 
> I get the following output from g++ (2.95.2 or the 12/14/99 snapshot):
> 
> % g++ -v -c gccerr.cpp
> Reading specs from /usr/local/gcc-exp/lib/gcc-lib/i686-pc-linux-gnu/2.96/specs
> gcc version 2.96 19991214 (experimental)
>  /usr/local/gcc-exp/lib/gcc-lib/i686-pc-linux-gnu/2.96/cpp -lang-c++ -v -D__GNUC__=2
> -D__GNUG__=2 -D__GNUC_MINOR__=96 -D__cplusplus -D__ELF__ -Dunix -D__i386__ -Dlinux -D
> __ELF__ -D__unix__ -D__i386__ -D__linux__ -D__unix -D__linux -Asystem(posix) -D__EXCE
> PTIONS -Acpu(i386) -Amachine(i386) -Di386 -D__i386 -D__i386__ -D__tune_pentiumpro__ g
> ccerr.cpp /tmp/ccRWqUbV.ii
> GNU CPP version 2.96 19991214 (experimental) (i386 Linux/ELF)
> #include "..." search starts here:
> #include <...> search starts here:
>  /home/facstaff/yarnall/include
>  /usr/local/gcc-exp/lib/gcc-lib/i686-pc-linux-gnu/2.96/../../../../include/g++-3
>  /usr/local/include
>  /usr/local/gcc-exp/lib/gcc-lib/i686-pc-linux-gnu/2.96/../../../../i686-pc-linux-gnu/
> include
>  /usr/local/gcc-exp/lib/gcc-lib/i686-pc-linux-gnu/2.96/include
>  /usr/include
> End of search list.
> The following default directories have been omitted from the search path:
> 
> End of omitted list.
>  /usr/local/gcc-exp/lib/gcc-lib/i686-pc-linux-gnu/2.96/cc1plus /tmp/ccRWqUbV.ii -quie
> t -dumpbase gccerr.cc -version -o /tmp/ccOdLk1H.s
> GNU C++ version 2.96 19991214 (experimental) (i686-pc-linux-gnu) compiled by GNU C ve
> rsion 2.96 19991214 (experimental).
> gccerr.cpp: In function `int main ()':
> gccerr.cpp:27: request for member `doit' in `u', which is of non-aggregate type `Umm
> () (Err)'
> 
> Cheers,
> Ken
> -- 
> Ken Yarnall
> Dept. of Mathematical Sciences
> Lebanon Valley College
> yarnall@lvc.edu, 717-867-6085
> 



More information about the Gcc-bugs mailing list