This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/71527] wrong type mismatch while template argument deduction/substitution
- From: "benni.buch at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Wed, 15 Jun 2016 17:58:56 +0000
- Subject: [Bug c++/71527] wrong type mismatch while template argument deduction/substitution
- Auto-submitted: auto-generated
- References: <bug-71527-4 at http dot gcc dot gnu dot org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71527
--- Comment #1 from Benjamin Buch <benni.buch at gmail dot com> ---
I simplified the example code:
//==================== Example ==================
// A compile time int-type
template < int I >
struct size{};
// The problem:
template < typename T, int N >
void f(size< N >, T(&&)[N]){}
int main(){
// OK: T is int
f(size< 2 >(), {0, 1});
// Bug: wrong type mismatch, T should be float
f< float >(size< 2 >(), {0, 1});
// OK: error conflicting types
/* f(size< 2 >(), {0, 1.f}); */
// Bug: wrong type mismatch, T should be float
f< float >(size< 2 >(), {0, 1.f});
}
//===============================================
~$ g++ -o main -std=c++14 main.cpp
bug.cpp: In function âint main()â:
bug.cpp:16:32: error: no matching function for call to âf(size<2>,
<brace-enclosed initializer list>)â
f< float >(size< 2 >(), {0, 1});
^
bug.cpp:8:6: note: candidate: template<class T, int N> void f(size<N>, T
(&&)[N])
void f(size< N >, T(&&)[N]){}
^
bug.cpp:8:6: note: template argument deduction/substitution failed:
bug.cpp:16:32: note: mismatched types âfloatâ and âintâ
f< float >(size< 2 >(), {0, 1});
^
bug.cpp:22:34: error: no matching function for call to âf(size<2>,
<brace-enclosed initializer list>)â
f< float >(size< 2 >(), {0, 1.f});
^
bug.cpp:8:6: note: candidate: template<class T, int N> void f(size<N>, T
(&&)[N])
void f(size< N >, T(&&)[N]){}
^
bug.cpp:8:6: note: template argument deduction/substitution failed:
bug.cpp:22:34: note: mismatched types âfloatâ and âintâ
f< float >(size< 2 >(), {0, 1.f});
^