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

ADL is invoked by the compiler when a postfix-expression in a function call is an unqualified-id. #2301

Closed
jabelloc opened this issue Aug 17, 2018 · 3 comments

Comments

@jabelloc
Copy link

jabelloc commented Aug 17, 2018

[basic.lookup.argdep]/1:

When the postfix-expression in a function call (8.5.1.2) is an unqualified-id, other namespaces not considered during the usual unqualified lookup (6.4.1) may be searched, and in those namespaces, namespace-scope friend function or function template declarations (14.3) not otherwise visible may be found. These modifications to the search depend on the types of the arguments (and for template template arguments, the namespace of the template argument).

If the compiler knows that a name in a postfix-expression is an unqualified-id of a function call, bullet point (3.3) in [basic.scope.argdep]/3 doesn't make sense, as the set X cannot contain a declaration that is not a function nor a function template.

[basic.scope.argdep]/3:

Let X be the lookup set produced by unqualified lookup (6.4.1) and let Y be the lookup set produced by argument dependent lookup (defined as follows). If X contains
(3.1) — a declaration of a class member, or
(3.2) — a block-scope function declaration that is not a using-declaration, or
(3.3) — a declaration that is neither a function nor a function template

@jwakely
Copy link
Member

jwakely commented Aug 17, 2018

as the set X cannot contain a declaration that is not a function nor a function template

That's not true.

struct F {
  int operator()(int i) { return i; }
};
F f;

int i = f(0);

f(0) is a function call, f is an unqualified-id, name lookup finds ::f which is an object of type F, not a function.

@jwakely jwakely closed this as completed Aug 17, 2018
@jabelloc
Copy link
Author

Thanks for your insight, it was very helpful.

@jabelloc
Copy link
Author

[over.call.object]/1:

If the postfix-expression E in the function call syntax evaluates to a class object of type “cv T”, then the set of candidate functions includes at least the function call operators of T. The function call operators of T are obtained by ordinary lookup of the name operator() in the context of (E).operator().

It seems to me your example still does not justify the need for [basic.scope.argdep]/(3.3), as there is no ADL in this case, as the postfix-expression is expanded with the name in between parentheses.

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