This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/37374] New: "using" shadows declaration
- From: "kduda at arastra dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 4 Sep 2008 17:01:40 -0000
- Subject: [Bug c++/37374] New: "using" shadows declaration
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
The following code (example A) compiles:
namespace N1 { void f() {} }
namespace N2 { void f(int) {} using N1::f; }
main() { N2::f(0); }
But this code does not compile (example B) because the compiler claims there is
no f(int) within N2:
namespace N1 { void f() {} }
namespace N2 { void f(int); using N1::f; }
void N2::f(int) {}
main() { N2::f(0); }
I do not have the C++ expertise to know whether the "using N1::f" should shadow
the previous use of the unqualified name "f" inside "N2", but I do think that
it should be consistent for function declarations vs function definitions.
That is, if "using N1::f" should shadow the prior use of "f" within "N2", then
example A should not compile because the N2::f with the (int) overload has been
shadowed. If "using N1::f" should not shadow the prior use of f within N2,
then example B should compile because N2::f(int) was properly declared in
namespace N2.
Example B used to compile in g++-4.1.2. It was in upgrading to 4.3.0 that code
in our tree that is like example B suddenly stopped compiling.
I apologize that I do not know what the bug is --- is g++ incorrectly allowing
example A to compile, or is it incorrectly giving an error with example B? I
do not know, but it seems that one must be wrong.
Also, I apologize in advance if gcc's behavior is correct here, and somehow it
is right that A should compile and B should not. I find the rules around
unqualified name resolution, "using", and function overloading difficult to
understand. Any explanation greatly appreciated.
Whatever the result, the workaround is easy of course --- just move the "using
N1::f" before any other use of "f" within N2. Then there is no question about
what sorts of uses of "f" should be shadowed.
Thanks,
-Ken
--
Summary: "using" shadows declaration
Product: gcc
Version: 4.3.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: kduda at arastra dot com
GCC build triplet: i386-redhat-linux
GCC host triplet: i386-redhat-linux
GCC target triplet: i386-redhat-linux
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37374