When a namespace declares a function, and then "uses" another function with the
same name from a different namespace, the using declaration seems to hide the
function declaration.  At least, when I define the function body later, the
comiler complains that the function wasn't declared in the namespace.  However,
if I "use" the function first, and THEN declare it in the namespace, the
definition of the function is accepted.  (It's easer to show code than explain.
 See below.)


Using built-in specs.
Target: i486-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 4.3.2-1ubuntu11'
--with-bugurl=file:///usr/share/doc/gcc-4.3/README.Bugs
--enable-languages=c,c++,fortran,objc,obj-c++ --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.3
--program-suffix=-4.3 --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.3.2 (Ubuntu 4.3.2-1ubuntu11) 
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-mtune=generic'
 /usr/lib/gcc/i486-linux-gnu/4.3.2/cc1plus -E -quiet -v -D_GNU_SOURCE asdf.cpp
-D_FORTIFY_SOURCE=2 -mtune=generic -fpch-preprocess -o asdf.ii
ignoring nonexistent directory "/usr/local/include/i486-linux-gnu"
ignoring nonexistent directory
"/usr/lib/gcc/i486-linux-gnu/4.3.2/../../../../i486-linux-gnu/include"
ignoring nonexistent directory "/usr/include/i486-linux-gnu"
#include "..." search starts here:
#include <...> search starts here:
 /usr/include/c++/4.3
 /usr/include/c++/4.3/i486-linux-gnu
 /usr/include/c++/4.3/backward
 /usr/local/include
 /usr/lib/gcc/i486-linux-gnu/4.3.2/include
 /usr/lib/gcc/i486-linux-gnu/4.3.2/include-fixed
 /usr/include
End of search list.
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-mtune=generic'
 /usr/lib/gcc/i486-linux-gnu/4.3.2/cc1plus -fpreprocessed asdf.ii -quiet
-dumpbase asdf.cpp -mtune=generic -auxbase asdf -version -fstack-protector -o
asdf.s
GNU C++ (Ubuntu 4.3.2-1ubuntu11) version 4.3.2 (i486-linux-gnu)
        compiled by GNU C version 4.3.2, GMP version 4.2.2, MPFR version 2.3.2.
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: dc8f858cacda993dd8f70837f0d9565d
asdf.cpp:15: error: ‘void A::f(int)’ should have been declared inside ‘A’

Source Code:

void f() {}

namespace A {
  void f(int);
  using ::f;
}

//
// With the function declaration in namespace A appearing first, the
// implementation below fails to compile.  Switch the order (such that the
// "using" appears first) and then it compiles.
//
// g++ /tmp/asdf.cpp
// /tmp/asdf.cpp:15: error: ‘void A::f(int)’ should have been declared inside
‘A’
void A::f(int a) {}

int main() {
  A::f(1);
}


-- 
           Summary: using declaration appears to hide local declaration
           Product: gcc
           Version: 4.3.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: cuzdav at gmail dot com


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

Reply via email to