C++ Logo

std-discussion

Advanced search

Re: C++ 20, Unqualified name look: a confusing relative to postfix expressions.

From: Andrew Schepler <aschepler_at_[hidden]>
Date: Thu, 5 Sep 2019 17:34:16 -0400
On Thu, Sep 5, 2019 at 12:49 PM Vladimir Grigoriev <vlad.moscow_at_[hidden]> wrote:
> #include <iostream>
>
> struct A
> {
> friend void f( A &a );
> static void g( A &a )
> {
> f( a );
> }
>
> private:
> int i = 10;
> };
>
> void f( A &a ) { std::cout << "F( " << a.i << " )\n"; }
>
>
> int main()
> {
> A a;
> A::g( a );
> }

This example is well-formed, but because the use of "f" inside the
body of A::g is found by argument-dependent lookup
([basic.lookup.argdep]), since it has the syntax of a function call
and an argument has type A. The name "f" is not otherwise visible at
that point. Change the function's parameter from A& to int& or most
other types, and the program is ill-formed. Try to do "void
(*fptr)(A&) = &f;" and the program is ill-formed.

Received on 2019-09-05 16:36:34