This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/71527] wrong type mismatch while template argument deduction/substitution


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});                                            
                                  ^

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]