https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106903
Bug ID: 106903
Summary: Incorrectly accepts call to function template when
deduced type doesn't match adjusted type
Product: gcc
Version: 13.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: arthur.j.odwyer at gmail dot com
Target Milestone: ---
// https://godbolt.org/z/T1vPGYash
template<class T, int N>
struct Array {
template<int M>
operator Array<T, M>() const;
};
template<class T, class U>
void foo(Array<T, sizeof(U)> x,
Array<U, sizeof(T)> y);
int main()
{
foo(Array<int, 1>(), Array<char, 6>());
}
My understanding is that template type deduction on the call to `foo` should
fail, because even though we can unambiguously deduce [T=int, U=char], and even
though the actual argument's type Array<char,6> is CONVERTIBLE to the formal
parameter's type Array<char,4>, it's not actually the same type. My
understanding is that a parameter that contributes to deduction must have the
same type as its corresponding function argument.
MSVC correctly rejects with this confusing message-spew:
<source>(13): error C2664: 'void foo<int,char>(Array<int,1>,Array<char,4>)':
cannot convert argument 2 from 'Array<char,6>' to 'Array<char,4>'
<source>(13): note: Binding to reference
<source>(13): note: followed by
<source>(13): note: Call to user-defined-conversion 'Array<char,6>::operator
Array<char,4>(void) const<4>'
<source>(4): note: see declaration of 'Array<char,6>::operator Array<char,4>'
<source>(13): note: followed by
<source>(13): note: Exactly the same type
<source>(8): note: see declaration of 'foo'
Clang correctly rejects with this message:
<source>:13:5: error: no matching function for call to 'foo'
foo(Array<int, 1>(), Array<char, 6>());
^~~
<source>:8:6: note: candidate template ignored: deduced type 'Array<[...],
sizeof(int) aka 4>' of 2nd parameter does not match adjusted type 'Array<[...],
6>' of argument [with T = int, U = char]
void foo(Array<T, sizeof(U)> x,
^