This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
problem with uncomplete type
- To: bug-gcc at gnu dot org
- Subject: problem with uncomplete type
- From: Ulrich Lauther <ulrich dot lauther at mchp dot siemens dot de>
- Date: Fri, 22 Sep 2000 09:45:53 +0200 (MET DST)
- Reply-To: Ulrich dot Lauther at mchp dot siemens dot de
The program below exposes two problems:
1. at the marked line, one would expect a compiler message, because an uncomplete
type is used for template instantiation
2. If the method funny() is "commented in", the program gives a wrong result
(I guess due to a wrong cast, which is caused by the incomplete type info).
I append the full source and a typescript of compilation.
The typescript is made with 2.95.1, but 2.95.2 has the same problem.
Kind regards
-ulrich lauther
********************** source ***********************************
#include <stdio.h>
#include <stdlib.h>
struct dlink0 {
dlink0* next;
dlink0* last;
inline dlink0() : next(0), last(0) {}
inline dlink0* get_last() const { return last;}
inline dlink0* set_last(dlink0* p) { return last = p;}
};
template <class L>
class list_base {
L* tail;
public:
inline list_base() : tail(0) {
}
inline void append(L* a) {
if (tail) {
a->next = tail->next;
a->set_last(tail);
a->next->set_last(tail->next = a);
}
else tail = a->next = a->set_last(a);
tail = a;
}
inline L* first() const { return tail ? tail->next : (L*) 0; }
}; // list_base
template <class T, class L>
class ilist : private list_base<L> {
int elements;
public:
inline ilist() : elements(0) { // constructor
}
inline void append(const T* a) {
list_base<L>::append((T*)a);
elements++;
}
inline T* first() {return (T*) list_base<L>::first();}
}; // ilist
class MessLink;
struct space {
int x[2];
};
class Fudge {
public:
ilist<MessLink,dlink0> mess_links; // would expect compiler complait here!!!
/* without the (unused) method funny() everything runs o.k.
with funny(), the program prints two different values, which is wrong
*/
MessLink* funny() {
return mess_links.first();
}
};
class MessLink : public space,
public dlink0 {
}; // MessLink
int main() {
Fudge f;
MessLink* tp = new MessLink;
printf("append %p\n",tp);
f.mess_links.append(tp);
printf("first: %p\n",f.mess_links.first());
}
************************** compilation **********************************
Script started on Fri Sep 22 09:41:13 2000
bash$ g++ -v bug.C
Reading specs from /usr/local/lib/gcc-lib/i686-pc-linux-gnulibc1/2.95.1/specs
gcc version 2.95.1 19990816 (release)
/usr/local/lib/gcc-lib/i686-pc-linux-gnulibc1/2.95.1/cpp -lang-c++ -v -D__GNUC__=2 -D__GNUG__=2 -D__GNUC_MINOR__=95 -D__cplusplus -D__ELF__ -Dunix -D__i386__ -Dlinux -D__ELF__ -D__unix__ -D__i386__ -D__linux__ -D__unix -D__linux -Asystem(posix) -D__EXCEPTIONS -Acpu(i386) -Amachine(i386) -Di386 -D__i386 -D__i386__ -Di686 -Dpentiumpro -D__i686 -D__i686__ -D__pentiumpro -D__pentiumpro__ bug.C /tmp/ccArL954.ii
GNU CPP version 2.95.1 19990816 (release) (i386 Linux/ELF)
#include "..." search starts here:
#include <...> search starts here:
/usr/local/lib/gcc-lib/i686-pc-linux-gnulibc1/2.95.1/../../../../include/g++-3
/usr/local/include
/usr/local/lib/gcc-lib/i686-pc-linux-gnulibc1/2.95.1/../../../../i686-pc-linux-gnulibc1/include
/usr/local/lib/gcc-lib/i686-pc-linux-gnulibc1/2.95.1/include
/usr/include
End of search list.
The following default directories have been omitted from the search path:
End of omitted list.
/usr/local/lib/gcc-lib/i686-pc-linux-gnulibc1/2.95.1/cc1plus /tmp/ccArL954.ii -quiet -dumpbase bug.cc -version -o /tmp/ccq4ssvc.s
GNU C++ version 2.95.1 19990816 (release) (i686-pc-linux-gnulibc1) compiled by GNU C version 2.95.1 19990816 (release).
as -V -Qy -o /tmp/ccvjz7jS.o /tmp/ccq4ssvc.s
GNU assembler version 2.9.1 (i386-pc-linux-gnulibc1), using BFD version 2.9.1.0.19
/usr/local/lib/gcc-lib/i686-pc-linux-gnulibc1/2.95.1/collect2 -m elf_i386 -dynamic-linker /lib/ld-linux.so.1 /usr/lib/crt1.o /usr/lib/crti.o /usr/local/lib/gcc-lib/i686-pc-linux-gnulibc1/2.95.1/crtbegin.o -L/usr/local/lib/gcc-lib/i686-pc-linux-gnulibc1/2.95.1 -L/usr/local/i686-pc-linux-gnulibc1/lib -L/usr/local/lib /tmp/ccvjz7jS.o -lstdc++ -lm -lgcc -lc -lgcc /usr/local/lib/gcc-lib/i686-pc-linux-gnulibc1/2.95.1/crtend.o /usr/lib/crtn.o
bash$ a.out
append 0x8049c00
first: 0x8049c08
bash$ exit
exit
Script done on Fri Sep 22 09:41:48 2000
--
-lauther
----------------------------------------------------------------------------
Ulrich Lauther ph: +49 89 636 48834 fx: ... 636 42284
Siemens ZT SE 4 Internet: Ulrich.Lauther@mchp.siemens.de