Greetings,
g++ 4.1 compiles the following without warning, but should not:
struct B { };
struct OK1 {
typedef B X;
};
template <typename T>
struct A {
friend struct T::X;
};
int main() {
A<OK1> a;
A<OK1> b = a;
return(0);
}
The problem is in the definition of struct A where the friend statement
should cause an error where neither template parameter T nor typedef X can
be used in this elaborated type specifier (NOTE: the compiler correctly
catches the case when 'friend struct T;' is used).
For a related column by Bobby Schmidt of the former C/C++ User Journal, see
here:
http://www.ddj.com/dept/database/184401655
The information for the g++ version I am using and the machine that it's
running on follows:
g++ -v
Using built-in specs.
Target: i386-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man
--infodir=/usr/share/info --enable-shared --enable-threads=posix
--enable-checking=release --with-system-zlib --enable-__cxa_atexit
--disable-libunwind-exceptions
--with-gxx-include-dir=/usr/include/c++/3.4.3 --enable-libgcj-multifile
--enable-languages=c,c++,java,f95 --enable-java-awt=gtk --disable-dssi
--with-java-home=/usr/lib/jvm/java-1.4.2-gcj-1.4.2.0/jre
--with-cpu=generic --host=i386-redhat-linux
Thread model: posix
gcc version 4.1.0 20060515 (Red Hat 4.1.0-18)
The command line information is as follows:
g++ -ansi -pedantic -Wall sourcefile.cpp