This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

unqualified name lookup in namespace bug


Hi,
I think this is a bug with egcs, but I'm using the dec 96 draft standard
as a reference and it doesn't (appear to) give an explicit example of
what I think should happen. References I give in the trailing discussion
are to this version of the standard.

I'm using the 1998-07-27 snapshot. Here's the program
--begin uqlookup.ii
namespace A
{
  void f(int);
}

namespace B
{
  using namespace A;
  void f();
  void h();
}

using namespace B;

void g()
{
  f();
  f(1);
}

void B::h()
{
  f();
  f(1);
}
--end uqlookup.ii

Here's the session log
--begin log
nathan@laie:5215>uname -a                       
SunOS laie 5.5.1 Generic sun4u sparc SUNW,Ultra-1
nathan@laie:5216>egcs-0727-g++ -v -c uqlookup.ii
Reading specs from
/home/staff/nathan/solaris/local/SunOS_5/lib/gcc-lib/sparc-sun-solaris2.5.1/egcs-2.91.52/specs
gcc version egcs-2.91.52 19980727 (gcc2 ss-980609 experimental)

/home/staff/nathan/solaris/local/SunOS_5/lib/gcc-lib/sparc-sun-solaris2.5.1/egcs-2.91.52/cc1plus
uqlookup.ii -quiet -version -o /var/tmp/cclbRUxc.s
GNU C++ version egcs-2.91.52 19980727 (gcc2 ss-980609 experimental)
(sparc-sun-solaris2.5.1) compiled by GNU C version 2.8.1.
uqlookup.ii: In function `void h()':
uqlookup.ii:9: too many arguments to function `f()'
uqlookup.ii:24: at this point in file
--end log

I think ::g and B::h should have the same behaviour. I.e. both A::f(int)
and B::f() are available for overload resolution in the calls to f() and
f(1).

In ::g, we are in the global namespace. This contains a using directive
for namespace B, hence all the names in B are available. Unqualified
name lookup searches B and finds B::f(). But also, because B contains a
using directive for namespace A, we also consider names inside A, and
hence find A::f(int). para 2 of 3.4.1 `Unqualified name look up' appears
to support this `... declarations from the namespace nominated by the
using directive are considered members of that enclosing namespace.' As
we've found (at least one) instance of the name we were looking for,
name lookup terminates. para 1 of 3.4.1 tells us to terminate `...
scopes are searcg ... in the order listed ... name lookup ends as soon
as a declaration is found for the name'. Overload resolution then goes
on to select f() or f(int).

In B::h() we are in namespace B, and hence unqualified name lookup
commences there (after searching the local scope of B::h). In B we find
B::f(). It seems to me that the using directive is also visible, and
hence namespace A should also be searched, before terminating the
lookup.

Is my understanding correct (and hence a bug), or am I missing
something?

nathan
-- 
Dr Nathan Sidwell :: Computer Science Department :: Bristol University
      You can up the bandwidth, but you can't up the speed of light      
nathan@acm.org  http://www.cs.bris.ac.uk/~nathan/  nathan@cs.bris.ac.uk


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]