public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "arthur.j.odwyer at gmail dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/106903] New: Incorrectly accepts call to function template when deduced type doesn't match adjusted type Date: Sun, 11 Sep 2022 16:13:43 +0000 [thread overview] Message-ID: <bug-106903-4@http.gcc.gnu.org/bugzilla/> (raw) 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, ^
next reply other threads:[~2022-09-11 16:13 UTC|newest] Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-09-11 16:13 arthur.j.odwyer at gmail dot com [this message] 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
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-106903-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).