[Bug c++/23137] New: Difficulty accessing base template members from derived template
frank dot radish at marconi dot com
gcc-bugzilla@gcc.gnu.org
Fri Jul 29 18:14:00 GMT 2005
The piece of code attached compiled without errors under gcc 3.3.3 (Red Hat
Linux), but failed with 3.4.2 (Windows XP) and 3.4.3 (Solaris 2.8).
The information that I am sending in this report all pertains to 3.4.3 on
Solaris. But I also installed a version of Dev-C++ which installs on Windows
XP and it has g++ 3.4.2 and the same failure exists there.
<289 /us/fradish/C++ > /us/bfsbld/Compilers/gcc/3.4.3/sparc-sun-
solaris2.7/bin/g++ -v
Reading specs from /us/bfsbld/Compilers/gcc/3.4.3/sparc-sun-
solaris2.7/lib/gcc/sparc-sun-solaris2.7/3.4.3/specs
Configured with: /us/bfsbld/Compilers/gcc/3.4.3/src/gcc/configure --
prefix=/us/bfsbld/Compilers/gcc/3.4.3/sparc-sun-solaris2.7 --disable-shared --
disable-multilib
Thread model: posix
gcc version 3.4.3
<290 /us/fradish/C++ > uname -a
SunOS bfs-qah51 5.8 Generic_117350-01 sun4u sparc SUNW,Ultra-5_10
======== build script ===================
#!/bin/csh
set MAINDIR="/us/bfsbld/Compilers/gcc/3.4.3/sparc-sun-solaris2.7"
set GCC="${MAINDIR}/bin/g++"
set LIB="${MAINDIR}/lib"
set INCLUDE="${MAINDIR}/include"
set file=TListExample3WithScope.cpp
${GCC} -c $file -I ${INCLUDE} -save-temps
=======================================
In the attached file TListExample3WithScope.cpp, in line 84
(SLList::append()), you will see an unscoped
call to the inherited method bottom() and in line 85 is a commented-out
call that is scoped by the base class name. And in line 86 is an
unscoped reference to "cursor". If I use the unscoped versions of
these, I get these errors:
<294 /us/fradish/C++ > csh build
TListExample3WithScope.cpp: In member function `bool SLList<T>::append(const
T&)':
TListExample3WithScope.cpp:84: error: there are no arguments to `bottom' that
depend on a template parameter, so a declaration of `bottom' must be available
TListExample3WithScope.cpp:84: error: (if you use `-fpermissive', G++ will
accept your code, but allowing the use of an undeclared name is deprecated)
TListExample3WithScope.cpp:86: error: `cursor' undeclared (first use this
function)
TListExample3WithScope.cpp:86: error: (Each undeclared identifier is reported
only once for each function it appears in.)
If I use -fpermissive, the first error will just become a warning, but the
second remains. If I comile the same thing on
gcc 3.3.3, I do not encounter these errors. If I use all of the scoped
versions of all of these calls, the code compiles
and runs fine even on 3.4.x.
I can try to install a newer version of gcc (I guess you're up around 4.01
now), but wanted to report this.
If this is not an error, but something that I am doing wrong that was
tolerated in 3.3.3, can you let me
know?
P.S. Here is the info for the 3.3.3 build where this isn't a problem:
Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/3.3.3/specs
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --
infodir=/usr/share/info --enable-shared --enable-threads=posix --disable-
checking --disable-libunwind-exceptions --with-system-zlib --enable-
__cxa_atexit --host=i386-redhat-linux
Thread model: posix
gcc version 3.3.3 20040412 (Red Hat Linux 3.3.3-7)
=========================================================
//TListExample3WithScope.cpp
#include <cstdlib>
#include <iostream>
using namespace std;
template <typename T> struct SLEntry {
SLEntry<T> *next;
T data;
SLEntry( const T &dat, SLEntry<T> *nxt=NULL ) {
data = dat;
next = nxt;
}
~SLEntry(){}
};
template <typename T> class SLListCursor {
private:
protected:
SLEntry<T> *head;
SLEntry<T> *cursor;
SLListCursor(SLEntry<T> *h=NULL, SLEntry<T> *c=NULL){
head = h; cursor = c; }
public:
SLListCursor( const SLListCursor<T> & );
~SLListCursor(){}
void top() { cursor = head; }
void bottom();
void next();
bool atEnd();
bool getData( T & );
};
template <typename T>
SLListCursor<T>::SLListCursor( const SLListCursor<T> &sl) {
head = sl.head;
cursor = sl.cursor;
}
template <typename T>
void SLListCursor<T>::bottom() {
SLEntry<T> *previous = NULL;
if ( cursor == NULL ) { top(); }
while ( cursor != NULL) {
previous = cursor;
next();
}
cursor = previous;
}
template <typename T>
void SLListCursor<T>::next() {
if ( cursor != NULL) {
cursor = cursor->next;
}
}
template <typename T>
bool SLListCursor<T>::getData(T &dat) {
if ( cursor != NULL) {
dat = cursor->data;
return true;
}
return false;
}
template <typename T>
bool SLListCursor<T>::atEnd() {
if ( cursor == NULL) {
return true;
}
return false;
}
template <typename T> class SLList: public SLListCursor<T> {
private:
protected:
public:
SLList(): SLListCursor<T>() {}
~SLList(){}
// Compiler doesn't appear to see inherited methods/data
bool append( const T &value ) {
bottom();
//SLListCursor<T>::bottom();
SLEntry<T> *tail = cursor;
//SLEntry<T> *tail = SLListCursor<T>::cursor;
SLEntry<T> *newEnt = new SLEntry<T>( value, NULL );
SLListCursor<T>::cursor = newEnt;
if ( SLListCursor<T>::head == NULL ) {
SLListCursor<T>::head = SLListCursor<T>::cursor;
}
if ( tail != NULL) {
tail->next = SLListCursor<T>::cursor;
}
return true;
}
};
typedef SLList<int> IList;
typedef SLListCursor<int> IListCursor;
int main(int argc, char *argv[])
{
IList ilist;
for ( int j = 0; j < 5; j++ ) {
ilist.append(j);
}
ilist.top();
IListCursor icursor( ilist );
int i = 0;
int k = 0;
while ( ilist.getData( k ) ) {
printf("ilist data = %d\n", k );
icursor.top();
while ( icursor.getData( i ) ) {
printf(" icursor data = %d\n", i );
icursor.next();
}
ilist.next();
}
return 0;
}
--
Summary: Difficulty accessing base template members from derived
template
Product: gcc
Version: 3.4.3
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: frank dot radish at marconi dot com
CC: gcc-bugs at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23137
More information about the Gcc-bugs
mailing list