You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A template friend declaration may declare a member of a dependent type to be a friend. The friend declaration shall declare a function or specify a type with an elaborated-type-specifier, in either case with a nested-name-specifier ending with a simple-template-id, C, whose template-name names a class template. The template parameters of the template friend declaration shall be deducible from C ([temp.deduct.type]). In this case, a member of a specialization S of the class template is a friend of the class granting friendship if deduction of the template parameters of C from S succeeds, and substituting the deduced template arguments into the friend declaration produces a declaration that corresponds to the member of the specialization.
Consider a simplified example from the formal example that follows [temp.friend] p5
A<T> at #1 can be deduced from A<int> at #2, substitute the deduced template arguments into the friend declaration produce void A<int>::f();, whereas the member of the specialization is int A<int>::f();, according to [basic.scope#scope-3.3.1]
Two declarations correspond if they (re)introduce the same name, both declare constructors, or both declare destructors, unless
[...]
each declares a function or function template, except when
both declare functions with the same parameter-type-list,21 equivalent ([temp.over.link]) trailing requires-clauses (if any, except as specified in [temp.friend]), and, if both are non-static members, the same cv-qualifiers (if any) and ref-qualifier (if both have one), or
both declare function templates with equivalent parameter-type-lists, return types (if any), template-heads, and trailing requires-clauses (if any), and, if both are non-static members, the same cv-qualifiers (if any) and ref-qualifier (if both have one).
In this case, both declarations do not declare function templates, the variance of the return types of such two declarations is not considered when determining whether they correspond or not.
Should we say that?
substituting the deduced template arguments into the friend declaration produces a valid declaration that corresponds to the member of the specialization
Since [basic.link] p11 requires that any two declarations of an Entity shall have the same type. In this case, substitute int into #1 will cause an invalid declaration.
It’s deliberate that “corresponds” ignores return types, so that
void f();
int f();
declare one function (invalidly). (This approach works well across translation units since we need some means of recognizing when they might mangle the same way.)
In general, we do rely on [basic.link]/11 to reject “corresponds but…” cases, but that doesn’t apply well here because we describe this in terms of a substitution that might or might not actually be “processed” as a declaration. We should probably check the return types explicitly; it might be good to introduce a term for “corresponds and…”, which would largely reconstitute the prior usage of “would be a well-formed redeclaration of”.
[temp.friend] p5 says
Consider a simplified example from the formal example that follows [temp.friend] p5
A<T>
at#1
can be deduced fromA<int>
at#2
, substitute the deduced template arguments into the friend declaration producevoid A<int>::f();
, whereas the member of the specialization isint A<int>::f();
, according to [basic.scope#scope-3.3.1]In this case, both declarations do not declare function templates, the variance of the return types of such two declarations is not considered when determining whether they correspond or not.
Should we say that?
Since [basic.link] p11 requires that any two declarations of an Entity shall have the same type. In this case, substitute
int
into#1
will cause an invalid declaration.@opensdh @jensmaurer
The text was updated successfully, but these errors were encountered: