C++ Logo

STD-DISCUSSION

Advanced search

Subject: Re: C++ 20, Unqualified name look: a confusing relative to postfix expressions.
From: Vladimir Grigoriev (vlad.moscow_at_[hidden])
Date: 2019-09-05 11:49:26


Let's start from the very beginning.

For example it is unclear reading the C++ Standard whether this program is correct that is successfully compiled by the C++  gcc HEAD 10.0.0 20190

#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 );
}

Is the name of the friend function f is visible inside the definition of the static function A::g? With best regards,
Vlad from Moscow

You can meet me at http://cpp.forum24.ru/ or www.stackoverflow.com or http://ru.stackoverflow.com

>Четверг, 5 сентября 2019, 0:46 +03:00 от Andrew Schepler via Std-Discussion <std-discussion_at_[hidden]>:
>
>> It would thus seem that [class.friend]/7 should be deleted or should be changed to a note (possibly reworded).
>
>I agree.
>
>Though is it worth clarifying somewhere that non-definition
>declarations of the function follow the same rules? I mean, in a
>friend declaration which declares a function or function template,
>names in the return type, parameter list, exception specification, and
>any template parameters and default template arguments are looked up
>"in class scope", but for any other declaration of the same function
>or function template, those names are looked up using the usual rules
>starting with that declaration's enclosing declarative region. (The
>rule about using scope lookup for names after the declarator of a
>class member's definition outside the class definition doesn't apply
>since a friend function isn't really a class member.)
>
>For that matter, the same is true for non-function friend
>declarations, like in the template parameter list of a friend
>declaration of a class template, or in qualified names, decltype()
>syntax, and template arguments of a template-id when befriending just
>a single type. Would [basic.lookup.unqual]/9 be better if it talked
>about "a name in a friend declaration" rather than "a name used in the
>definition of a friend function defined inline in the class" and
>"other declarations of the same entity" instead of "if the friend
>function is not defined in the class"? Or can we take that as normally
>covered by the usual lookup rules, and the purpose of
>[basic.lookup.unqual]/9 is to make it clear the rule about member
>definitions outside class definitions does not apply to friends?
>
>-- Andrew Schepler
>--
>Std-Discussion mailing list
>Std-Discussion_at_[hidden]
>https://lists.isocpp.org/mailman/listinfo.cgi/std-discussion



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

Older Archives on Google Groups