Skip to content

[basic.lookup.argdep] Handling of friends is unclear since P1787 #831

@timsong-cpp

Description

@timsong-cpp

Full name of submitter (unless configured in github; will be published with the issue): Tim Song

Reference (section label): [basic.lookup.argdep]

Link to reflector thread (if any):

Issue description:

(From this StackOverflow question.)

Since P1787R6, [basic.lookup.argdep]/4.2 says that "Argument-dependent lookup finds all declarations of functions and function templates that [...] are declared as a friend of any class with a reachable definition in the set of associated entities". This notably omits the limitation that the said friends are members of one of the associated namespaces (or, for that matter, are members of namespaces instead of classes).

struct A;
namespace ns { int f(A&&); }
struct A {
    friend int ns::f(A&&);
};

int x = f(A{});

There is implementation divergence in the handling of this example (GCC trunk accepts with -std=c++20 since this commit; others reject).

The author of P1787R6 confirmed that no change in behavior was intended.

See also CWG143.

Suggested resolution:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions