C++ Logo

STD-DISCUSSION

Advanced search

Subject: The C++ 17 Standard, friend functions, their visibilities and definitions.
From: Vladimir Grigoriev (vlad.moscow_at_[hidden])
Date: 2019-12-17 17:14:40


There is a confusing that requires a clarification in the C++ Standard relative to friend function declarations.
 
On the one hand, according to the quote (10.3.1.2 Namespace member definitions)
 
2 Members of a named namespace can also be defined outside that namespace by explicit qualification (6.4.3.2)
of the name being defined, provided that the entity being defined was already declared in the namespace and
the definition appears after the point of declaration in a namespace that encloses the declaration's namespace
 
On the other hand, according to this quote
 
3 If a friend declaration in a non-local class first declares a class, function, class template or function template97
the friend is a member of the innermost enclosing namespace. The friend declaration does not by itself make
the name visible to unqualified lookup (6.4.1) or qualified lookup (6.4.3).
 
Now consider the program I provided in my question at Stackoverflow
 
https://stackoverflow.com/questions/59383156/c-17-friend-function-declaration-and-inline-namespace?noredirect=1#comment104958284_59383156
 
The program is compiled successfully except that the gcc compiler issues warnings.
 
However according to the quote #3 the program is ill-formed and the compilers should issue an error.
 
And a question arises: if there was a friend function declaration in a class may it be defined in the enclosing namespace despite that the name of the friend function is invisible in the namespace where it is declared?
 
I think that the Standard could make a clarification relative to such a situation.
 
With best regards,
(Vlad from Moscow).
 
 
 
 
 
You can meet me at http://cpp.forum24.ru/ or www.stackoverflow.com or http://ru.stackoverflow.com



STD-DISCUSSION list run by std-discussion-owner@lists.isocpp.org

Older Archives on Google Groups