Skip to content

CWG3186 [basic.lookup.argdep] ADL is performed for a name #891

@Endilll

Description

@Endilll

(This is a follow-up on a side discussion happened during discussion of CWG3174 during 2026-04-17 telecon.)

Consider the following example:

namespace N {
  struct C {
    friend void f(C);
    friend void g(C);
  };
}

void h() {
  f(N::C{});
}

Careful reading of [basic.lookup.argdep]/4 suggests that g is also found by ADL, because it's "declared as a friend of a class with a reachable definition in the set of associated entities". Note the lack of any name requirements in [basic.lookup.argdep]/4.2, and in [basic.lookup.argdep]/4 in general.

Suggested resolution

Change [basic.lookup.argdep] paragraph 4 as follows:

[. . .] Argument-dependent lookup for a name N finds all declarations of functions and function templates that
— are found by a search of for N in any associated namespace, or
have the same name as N and are declared as a friend ([class.friend]) of any class with a reachable definition in the set of associated entities, or
have the same name as N, are exported, are attached to a named module M ([module.interface]), do not appear in the translation unit containing the point of the lookup, and have the same innermost enclosing non-inline namespace scope as a declaration of an associated entity attached to M ([basic.link]).

If the lookup is for a N is dependent name ([temp.dep], [temp.dep.candidate]), the above lookup is also performed from each point in the instantiation context ([module.context]) of the lookup, additionally ignoring any declaration that appears in another translation unit, is attached to the global module, and is either discarded ([module.global.frag]) or has internal linkage.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions