This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

EGCS 1.1b: bug in using pointer to members in template args


Hi,

The following program fails to compile with EGCS 1.1b.
---- bug-3.cxx
#include <iostream.h>
#if !HAVE_STD
#define std
#endif

template <class T> struct I
{
    virtual ~I () {}
    virtual void *get (T *object) = 0;
};

template <class T, class U, U T::*Member> struct X : I<T>
{
    void *get (T *object) { return &(object->*Member); }
};

struct Y { int i; float j; };

int main (int, char **)
{
    Y			y = { 1, 2.0 };
    X<Y,int,&Y::i>	xi;
    X<Y,float,&Y::j>	xj;
    I<Y>		&ii = xi;
    I<Y>		&ij = xj;

    std::cout << "Y::i = " << *(int *)ii.get (&y) << "\n"
	      << "Y::j = " << *(float *)ij.get (&y) << "\n";
    return 0;
}
----

$ c++ -v bug-3.cxx                               
Reading specs from /usr/local/lib/gcc-lib/i686-pc-linux-gnu/egcs-2.91.57/specs
gcc version egcs-2.91.57 19980901 (egcs-1.1 release)
 /usr/local/lib/gcc-lib/i686-pc-linux-gnu/egcs-2.91.57/cpp -lang-c++ -v -undef -D__GNUC__=2 -D__GNUG__=2 -D__cplusplus -D__GNUC_MINOR__=91 -D__ELF__ -Dunix -Dlinux -D__ELF__ -D__unix__ -D__linux__ -D__unix -D__linux -Asystem(posix) -D__EXCEPTIONS -Asystem
(unix) -Acpu(i386) -Amachine(i386) -Di386 -D__i386 -D__i386__ -Di686 -Dpentiumpro -D__i686 -D__i686__ -D__pentiumpro -D__pentiumpro__ bug-3.cxx /tmp/ccvqrBJg.ii
GNU CPP version egcs-2.91.57 19980901 (egcs-1.1 release) (i386 Linux/ELF)
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/include/g++
 /usr/local/include
 /usr/local/i686-pc-linux-gnu/include
 /usr/local/lib/gcc-lib/i686-pc-linux-gnu/egcs-2.91.57/include
 /usr/include
End of search list.
 /usr/local/lib/gcc-lib/i686-pc-linux-gnu/egcs-2.91.57/cc1plus /tmp/ccvqrBJg.ii -quiet -dumpbase bug-3.cc -version -o /tmp/ccQTvg3o.s
GNU C++ version egcs-2.91.57 19980901 (egcs-1.1 release) (i686-pc-linux-gnu) compiled by GNU C version egcs-2.91.57 19980901 (egcs-1.1 release).
bug-3.cxx: In instantiation of `X<Y,int,1>::get<Y, int, 1>(Y *)':
bug-3.cxx:27:   instantiated from here
bug-3.cxx:14: object `1' cannot be used as template argument
bug-3.cxx:14: object `1' cannot be used as template argument
bug-3.cxx:14: confused by earlier errors, bailing out

Cheers,
//lat
--
With sufficient thrust, pigs fly just fine.  However, this is not
necessarily a good idea.  It is hard to be sure where they are going
to land, and it could be dangerous sitting under them as they fly
overhead.  --RFC1925, "The Twelve Networking Truths"



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]