Skip to content

Unqualified lookup for friend elaborated-type-specifier in local classes escapes the nearest enclosing block scope #155907

@ckwastra

Description

@ckwastra

Test code (CE):

struct A {
  template <class T> using type = typename T::type;
};
void f() {
  class B {
    friend class A;
    using type = void;
  };
  struct A {
    // Clang/MSVC: error ❌
    //    GCC/EDG: OK    ✅
    using type = B::type;
  };
  // Clang/MSVC: OK    ❌
  //    GCC/EDG: error ✅
  using type = ::A::type<B>;
}

According to [dcl.type.elab]/4:

Any unqualified lookup for the identifier (in the first case) does not consider scopes that contain the nearest enclosing namespace or block scope; [...]

Therefore, in the declaration friend class A above, ::A (in global scope) should not be found. The friendship of B should instead be granted to the local class A declared inside f.

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:frontendLanguage frontend issues, e.g. anything involving "Sema"

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions