Hi,

I have the following code and I wonder why C++ complains.

namespace S {

class L;
class S;

}

using namespace S;

class C {
    void m(::S::L *l) {};
};

$ g++ main.5.cpp
main.5.cpp:12: error: 'struct S::S::L' has not been declared

Shouldn't it be clear that I wan't to access class L in
namespace S and not some L of class S in namespace S which
doesn't exist anyway ?

Couriously I only get this error on some compilers:
gcc 4.1 and gcc 4.2.3 produce this error while
gcc 3.2.2 and xlc work as expected.

John Love-Jensen tested this code with the EDG frontend which didn't complain:
> Not that I can cite chapter/verse of ISO 14882, rather I just tested against
> the EDG front end, and EDG accepted the code.  (I have strong confidence
> that the EDG front end is fully compliant with ISO 14882.)

gcc -v: (with this behavior)
$ gcc -v
Using built-in specs.
Target: x86_64-suse-linux
Configured with: ../configure --enable-threads=posix --prefix=/usr
--with-local-prefix=/usr/local --infodir=/usr/share/info
--mandir=/usr/share/man --libdir=/usr/lib64 --libexecdir=/usr/lib64
--enable-languages=c,c++,objc,fortran,java,ada --enable-checking=release
--with-gxx-include-dir=/usr/include/c++/4.1.0 --enable-ssp --disable-libssp
--enable-java-awt=gtk --enable-gtk-cairo --disable-libjava-multilib
--with-slibdir=/lib64 --with-system-zlib --enable-shared --enable-__cxa_atexit
--enable-libstdcxx-allocator=new --without-system-libunwind --with-cpu=generic
--host=x86_64-suse-linux
Thread model: posix
gcc version 4.1.0 (SUSE Linux)

gcc -v: (with this behavior)
Using built-in specs.
Target: i486-linux-gnu
Configured with: ../src/configure -v
--enable-languages=c,c++,fortran,objc,obj-c++,treelang --prefix=/usr
--enable-shared --with-system-zlib --libexecdir=/usr/lib
--without-included-gettext --enable-threads=posix --enable-nls
--with-gxx-include-dir=/usr/include/c++/4.2 --program-suffix=-4.2
--enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --enable-mpfr
--enable-targets=all --enable-checking=release --build=i486-linux-gnu
--host=i486-linux-gnu --target=i486-linux-gnu
Thread model: posix
gcc version 4.2.3 (Ubuntu 4.2.3-2ubuntu7)

gcc -v: (without this behavior)
Reading specs from /usr/lib/gcc-lib/i486-suse-linux/3.2.2/specs
Configured with: ../configure --enable-threads=posix --prefix=/usr
--with-local-prefix=/usr/local --infodir=/usr/share/info
--mandir=/usr/share/man --libdir=/usr/lib
--enable-languages=c,c++,f77,objc,java,ada --enable-libgcj
--with-gxx-include-dir=/usr/include/g++ --with-slibdir=/lib --with-system-zlib
--enable-shared --enable-__cxa_atexit i486-suse-linux
Thread model: posix
gcc version 3.2.2

$ g++ -v -save-temps main.5.cpp 
Using built-in specs.
Target: x86_64-suse-linux
Configured with: ../configure --enable-threads=posix --prefix=/usr
--with-local-prefix=/usr/local --infodir=/usr/share/info
--mandir=/usr/share/man --libdir=/usr/lib64 --libexecdir=/usr/lib64
--enable-languages=c,c++,objc,fortran,java,ada --enable-checking=release
--with-gxx-include-dir=/usr/include/c++/4.1.0 --enable-ssp --disable-libssp
--enable-java-awt=gtk --enable-gtk-cairo --disable-libjava-multilib
--with-slibdir=/lib64 --with-system-zlib --enable-shared --enable-__cxa_atexit
--enable-libstdcxx-allocator=new --without-system-libunwind --with-cpu=generic
--host=x86_64-suse-linux
Thread model: posix
gcc version 4.1.0 (SUSE Linux)
 /usr/lib64/gcc/x86_64-suse-linux/4.1.0/cc1plus -E -quiet -v -D_GNU_SOURCE
main.5.cpp -mtune=generic -fpch-preprocess -o main.5.ii
#include "..." search starts here:
#include <...> search starts here:
 /usr/include/c++/4.1.0
 /usr/include/c++/4.1.0/x86_64-suse-linux
 /usr/include/c++/4.1.0/backward
 /usr/local/include
 /usr/lib64/gcc/x86_64-suse-linux/4.1.0/include
 /usr/lib64/gcc/x86_64-suse-linux/4.1.0/../../../../x86_64-suse-linux/include
 /usr/include
End of search list.
 /usr/lib64/gcc/x86_64-suse-linux/4.1.0/cc1plus -fpreprocessed main.5.ii -quiet
-dumpbase main.5.cpp -mtune=generic -auxbase main.5 -version -o main.5.s
GNU C++ version 4.1.0 (SUSE Linux) (x86_64-suse-linux)
        compiled by GNU C version 4.1.0 (SUSE Linux).
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 27c671cf0665589b0d83cdf045d73d76
main.5.cpp:12: error: ‘struct S::S::L’ has not been declared


-- 
           Summary: namespace and class within with similar name
           Product: gcc
           Version: 4.2.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: alexander dot werth at gmx dot de


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37030

Reply via email to