https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66836

            Bug ID: 66836
           Summary: inconsistent unqualified lookup for friend declaration
           Product: gcc
           Version: 5.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: barry.revzin at gmail dot com
  Target Milestone: ---

Consider the following code, courtesy of Belloc
(http://stackoverflow.com/q/31348475/2069064):

struct Outer {
    void f() { }
    class C { };

    class Inner {
        friend class C;
        friend void f();
        static const int i = 0;
    };
};

void f() { int i = Outer::Inner::i; }
class C { int i = Outer::Inner::i; };

int main() { }

According to [namespace.memdef]/3, "the lookup to determine whether the entity
has been previously declared shall not consider any scopes outside the
innermost enclosing namespace." 

There's some confusion as to what "outside" means in this context, but
regardless both GCC and Clang are inconsistent in their interpretation. Either
it means exclusively the innermost enclosing namespace (in which case both ::f
and ::C should be friends) or it just means stop at the innermost enclosing
namespace (in which case both Outer::f and Outer::C should be friends). But in
this case, both GCC and Clang friend ::f and Outer::C, which is a bug in one
direction or the other.

Reply via email to