The following code builds successfully with g++, even though it appears to be in conflict with 7.3.1.2, paragraph 2 of the C++ standard. A class member is declared in one namespace, then defined in another.
The code (incorrectly) compiles on several version of gcc (3.2, 3.3, 4.0.2), and (correctly) fails for many other compilers (Intel, IBM, SGI, PGI). The output from other compilers that fail point to (with more or less clairty) to section 7.3.1.2 in the warning error messages. Here is the example code: //------------------------------------------ // trouble.cc namespace A { class X { public: X( int i_in ); const int i; }; } namespace B { A::X::X(int i_in) : i(2*i_in) {} } //------------------------------------------ The following modified version of the sample in the code listed in the standard, 7.3.1.2, paragraph 2, page 114, fails to compile with g++ as expected. (The exact code listed in the standard also fails to compile as expected, but the example below is closer to the example above.) //------------------------------------------ namespace Q { void f(); } namespace R { void Q::f() { } } //------------------------------------------ I am using gcc-4.0.2 on OS X 10.4.5, or uname -mpsvr Darwin 8.5.0 Darwin Kernel Version 8.5.0: Sun Jan 22 10:38:46 PST 2006; root:xnu-792.6.61.obj~1/RELEASE_PPC Power Macintosh powerpc I built gcc with the following configure line: ../gcc-4.0.2/configure --prefix=/Users/tabrunn/gcc-test --enable-languages=c,c++ The compiler options were: g++ -Wall -Weffc++ -pedantic -c trouble.cc or g++ -Wall -c trouble.cc or g++ -c trouble.cc There was no output, except a trouble.o file. I have tried this with several versions of g++ (3.2, 3.3, Apple's 4.0) on both Intel Linux machines and my PowerPC Darwin machine, and all have the same behavior. If this is a g++ extension and not a bug, it would be nice to get a warning message from -Wall. -- Summary: namespace resolution problems Product: gcc Version: 4.0.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: tabrunn at sandia dot gov GCC build triplet: powerpc-apple-darwin8.5.0 GCC host triplet: powerpc-apple-darwin8.5.0 GCC target triplet: powerpc-apple-darwin8.5.0 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26403