public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/106903] New: Incorrectly accepts call to function template when deduced type doesn't match adjusted type
@ 2022-09-11 16:13 arthur.j.odwyer at gmail dot com
2022-09-13 20:16 ` [Bug c++/106903] " ppalka at gcc dot gnu.org
2022-09-19 18:52 ` mpolacek at gcc dot gnu.org
0 siblings, 2 replies; 3+ messages in thread
From: arthur.j.odwyer at gmail dot com @ 2022-09-11 16:13 UTC (permalink / raw)
To: gcc-bugs
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,
^
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c++/106903] Incorrectly accepts call to function template when deduced type doesn't match adjusted type
2022-09-11 16:13 [Bug c++/106903] New: Incorrectly accepts call to function template when deduced type doesn't match adjusted type arthur.j.odwyer at gmail dot com
@ 2022-09-13 20:16 ` ppalka at gcc dot gnu.org
2022-09-19 18:52 ` mpolacek at gcc dot gnu.org
1 sibling, 0 replies; 3+ messages in thread
From: ppalka at gcc dot gnu.org @ 2022-09-13 20:16 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106903
Patrick Palka <ppalka at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |ppalka at gcc dot gnu.org
See Also| |https://gcc.gnu.org/bugzill
| |a/show_bug.cgi?id=103333
--- Comment #1 from Patrick Palka <ppalka at gcc dot gnu.org> ---
PR103333 looks similar/related
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c++/106903] Incorrectly accepts call to function template when deduced type doesn't match adjusted type
2022-09-11 16:13 [Bug c++/106903] New: Incorrectly accepts call to function template when deduced type doesn't match adjusted type arthur.j.odwyer at gmail dot com
2022-09-13 20:16 ` [Bug c++/106903] " ppalka at gcc dot gnu.org
@ 2022-09-19 18:52 ` mpolacek at gcc dot gnu.org
1 sibling, 0 replies; 3+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2022-09-19 18:52 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106903
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |mpolacek at gcc dot gnu.org
Status|UNCONFIRMED |NEW
Ever confirmed|0 |1
Last reconfirmed| |2022-09-19
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-09-19 18:52 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-11 16:13 [Bug c++/106903] New: Incorrectly accepts call to function template when deduced type doesn't match adjusted type arthur.j.odwyer at gmail dot com
2022-09-13 20:16 ` [Bug c++/106903] " ppalka at gcc dot gnu.org
2022-09-19 18:52 ` mpolacek at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).