[temp.deduct.partial] p4 Partial ordering for a non-deduced context parameter
Nobody has claimed this yet.
- Dominant language
- TeX
- Stars
- 221
- Forks
- 813
- Avg merge
- 16h 4m
- Merged PRs (30d)
- 36
Description
In c++17, [temp.deduct.partial] p4 says
Each type nominated above from the parameter template and the corresponding type from the argument template are used as the types of P and A. If a particular P contains no template-parameters that participate in template argument deduction, that P is not used to determine the ordering.
After CWG2235, the emphasized wording was removed. Consider this example
template<class U>
struct unknow_content{
using type = U;
};
template<class T>
void fun(typename unknow_content<T>::type, T){
std::cout<<"1\n";
}
template<class T, class U>
void fun(T, U){
std::cout<<"2\n";
}
int main(){
fun(0,0);
}
According to [temp.deduct.partial#3.1], the P/A pairs are formed from function parameter types without other requirements. Hence, in this partial ordering, the set of P/A pairs that determine the ordering consists of
P = typename unknow_content<T>::type / A = T' , P = T / A = U'
P = T' / A = typename unknow_content<T>::type , P = U' / A = T
Which is more specialized than the other is essentially determined by that
If deduction succeeds for a given type, the type from the argument template is considered to be at least as specialized as the type from the parameter template.
Function template F is at least as specialized as function template G if, for each pair of types used to determine the ordering, the type from F is at least as specialized as the type from G. F is more specialized than G if F is at least as specialized as G and G is not at least as specialized as F.
Without the impact of the removed rule
If a particular P contains no template-parameters that participate in template argument deduction, that P is not used to determine the ordering.
[temp.deduct.type] p4
In certain contexts, however, the value does not participate in type deduction, but instead uses the values of template arguments that were either deduced elsewhere or explicitly specified.
does not apply here since P = typename unknow_content<T>::type does participate in deduction.
We can arguably says, the deduction fails for this pair P = typename unknow_content<T>::type / A = T' since that
If type deduction cannot be done for any P/A pair, ..., template argument deduction fails
Hence, in this example, #1 should have been more specialized than #2 after CWG2235, however, all implementations say they're ambiguous. See https://godbolt.org/z/9P1Tjr3WK
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.deduct.partial] p3.1 and p4, [temp.deduct.type] p4, and the CWG2235 change described in the issue. Reproduce the example using the linked Compiler Explorer case and compare the implementations' ambiguity result with the proposed deduction analysis. Done means determining the standard-conforming partial-ordering outcome and resolving the wording or interpretation discrepancy.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100