https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71527

            Bug ID: 71527
           Summary: wrong type mismatch while template argument
                    deduction/substitution
           Product: gcc
           Version: 6.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: benni.buch at gmail dot com
  Target Milestone: ---

//==================== Example ==================
// Convert C-String to int
template < int N >
constexpr int parse_int(char const(&arr)[N])noexcept{
        int number = 0;
        int base = 1;
        for(int i = 0; i < N; ++i){
                number += (static_cast< int >(arr[N - 1 - i]) - 48) * base;
                base *= 10;
        }
        return number;
}

// A compile time int-type
template < int I >
struct size{};

// Create a compile time int via user literals
template < char ... S >
constexpr auto operator"" _S()noexcept{
        return size< parse_int< sizeof...(S) >({S ...}) >();
}


// The problem:
template < typename T, int N >
void f(size< N >, T(&&)[N]){}


int main(){
        // OK: T is int
        f(2_S, {0, 1});

        // Bug: wrong type mismatch, T should be float
        f< float >(2_S, {0, 1});

        // OK: error conflicting types
        /* f(2_S, {0, 1.f}); */

        // Bug: wrong type mismatch, T should be float
        f< float >(2_S, {0, 1.f});
}
//===============================================

clang compiles it well, GCC reports a type mismatch:

~$ g++ -o main -std=c++14 main.cpp 
bug.cpp: In function ‘int main()’:
bug.cpp:34:24: error: no matching function for call to ‘f(size<2>,
<brace-enclosed initializer list>)’
  f< float >(2_S, {0, 1});
                        ^
bug.cpp:26:6: note: candidate: template<class T, int N> void f(size<N>, T
(&&)[N])
 void f(size< N >, T(&&)[N]){}
      ^
bug.cpp:26:6: note:   template argument deduction/substitution failed:
bug.cpp:34:24: note:   mismatched types ‘float’ and ‘int’
  f< float >(2_S, {0, 1});
                        ^
bug.cpp:40:26: error: no matching function for call to ‘f(size<2>,
<brace-enclosed initializer list>)’
  f< float >(2_S, {0, 1.f});
                          ^
bug.cpp:26:6: note: candidate: template<class T, int N> void f(size<N>, T
(&&)[N])
 void f(size< N >, T(&&)[N]){}
      ^
bug.cpp:26:6: note:   template argument deduction/substitution failed:
bug.cpp:40:26: note:   mismatched types ‘float’ and ‘int’
  f< float >(2_S, {0, 1.f});

Reply via email to