C++ Logo

STD-DISCUSSION

Advanced search

Subject: Re: C++ 20, Unqualified name look: a confusing relative to postfix expressions.
From: Andrew Schepler (aschepler_at_[hidden])
Date: 2019-09-05 16:34:16


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.


STD-DISCUSSION list run by herb.sutter at gmail.com

Older Archives on Google Groups