Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

An improvement to ADL for the name declared by a friend declaration #5302

Open
xmh0511 opened this issue Feb 18, 2022 · 2 comments
Open

An improvement to ADL for the name declared by a friend declaration #5302

xmh0511 opened this issue Feb 18, 2022 · 2 comments

Comments

@xmh0511
Copy link
Contributor

xmh0511 commented Feb 18, 2022

[basic.lookup.argdep] p4 is saying:

Argument-dependent lookup finds all declarations of functions and function templates that

  • are found by a search of any associated namespace, or
  • are declared as a friend ([class.friend]) of any class with a reachable definition in the set of associated entities, or

It sounds like we impose no requirement on the friend declarations when ADL. According to [dcl.meaning.general] p2, the declaration of a friend declaration does not bind a name. we define the concept for wording search that works on the name is bound. It is not suitable for friend declaration. The improvement is:

Argument-dependent lookup finds all declarations of functions and function templates that

  • [...], or
  • are declared as a friend of any class with a reachable definition in the set of associated entities, where the terminal names of the declarator-ids of the declarations are the same as the name that is being found.
@languagelawyer
Copy link
Contributor

the terminal names of the declarator-ids of the declarations are the same as the name that is being found

What about

struct S;
namespace N
{
    void f(S&);
}

struct S
{
    friend void N::f(S&);
};

void f(S&&);

int main()
{
    S s;
    f(s);
}

@xmh0511
Copy link
Contributor Author

xmh0511 commented Feb 18, 2022

@languagelawyer Yes, you're correct. We should modify the above wording to that

are declared as a friend of any class T with a reachable definition in the set of associated entities, and whose target scopes are the namespace of which T is a member and the terminal names of the declarator-ids are the same as the name that is being found.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants