BUG:unqualified name lookup is buggy when friend declarations are involved

Martin von Loewis martin@mira.isdn.cs.tu-berlin.de
Fri Sep 18 17:13:00 GMT 1998


[standard text]
>   3.4.1  Unqualified name look up                  [basic.lookup.unqual]
>           typedef int f;
>           struct A {
>                   friend void f(A &);
>                   operator int();
>                   void g(A a) {
>                           f(a);
>                   }
>           };
[g++ error message]
> main.cpp:19: previous non-function declaration `typedef int f'

> So the current behavior is buggy right?

Yes, but the standard example is also buggy. The code is ill-formed;
the friend declaration does introduce a (global) namespace member,
which conflicts with the typedef.

In comp.lang.std.c++, somebody provided a correct example:

struct Outer{
          typedef int f;
          struct A {
                  friend void f(A &);
                  operator int();
                  void g(A a) {
                          f(a);
                  }
          };
};

OTOH, g++ does not hide friend functions. As a result, this code
doesn't work with g++, although it should. I'm not sure how hard that
is; in the past, you couldn't hide the name as there was no Koenig
lookup to find it anyway.

Regards,
Martin




More information about the Gcc-bugs mailing list