[temp.friend] p5 Two declarations correspond can ignore the return types
Nobody has claimed this yet.
- Dominant language
- TeX
- Stars
- 221
- Forks
- 813
- Avg merge
- 16h 4m
- Merged PRs (30d)
- 36
Description
[temp.friend] p5 says
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
template<class T> struct A {
void f();
};
template<> struct A<int> {
int f();
};
class C {
template<class T> friend void A<T>::f(); // #1
int c;
};
int A<int>::f(){ // #2
C c;
return 0;
}
int main(){
}
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.
@opensdh @jensmaurer
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with [temp.friend] p5 and the cited [basic.scope#scope-3.3.1] and [basic.link] p11, then examine the simplified example and its declarations. Done means resolving whether the return-type wording is sufficient and determining the precise standard-text change, if any.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100