2012-12-17 8 views
5

Biorąc pod uwagę następujący kod:dwa różne wyniki na GCC 4.6 i 4.7 dla szablonu szablonu odliczenia

#include <iostream> 
#include <vector> 
#include <array> 
#include <type_traits> 

// Version A 
template<typename T> 
void f(const T& x) 
{ 
    std::cout<<"Version A"<<std::endl; 
} 

// Version B 
template<typename... T1, template<typename...> class T> 
void f(const T<T1...>& x) 
{ 
    std::cout<<"Version B"<<std::endl; 
} 

// Version C 
template<typename T1 = double, typename TN = size_t, template<typename, TN...> class T, TN... N> 
void f(const T<T1, N...>& x) 
{ 
    std::cout<<"Version C"<<std::endl; 
} 

// Main 
int main(int argc, char* argv[]) 
{ 
    f(double()); 
    f(std::vector<double>()); 
    f(std::array<double, 3>()); 
    return 0; 
} 

GCC 4.6.2 na Windows otrzymujemy:

Version A 
Version B 
Version C 

i GCC 4.7.1 na Linux daje :

Version A 
Version B 
Version A 

Pytanie brzmi: DLACZEGO? Czy jest to błąd, czy niezdefiniowane zachowanie? Czy powinienem opublikować go w raporcie o błędach GCC?

+2

Czy ta nie zapytał wcześniej dzisiaj? – Gorpik

+0

Usunięcie '= size_t' naprawia. – Pubby

+0

@Gorpik: był to w przybliżeniu ten sam kod, ale nie dla tego samego pytania/przyczyny. – Vincent

Odpowiedz

4

Wygląda na to, że błąd w gcc 4.7.x (4.7.2 ma ten sam problem). Oto prostszy przykład:

template<int N> struct S {}; 
template<typename T = int, T N> void f(S<N>) {} 
int main() { S<1> s; f(s); } 

gcc 4.7.2 nie powiedzie się z:

source.cpp:3:25: error: no matching function for call to 'f(S<1>&)' 
source.cpp:3:25: note: candidate is: 
source.cpp:2:38: note: template<class T, T N> void f(S<N>) 
source.cpp:2:38: note: template argument deduction/substitution failed: 
+1

Czy możesz zgłosić ten błąd do GCC? – Vincent

+2

Zgłosiłem błąd tutaj: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55724 – Vincent

Powiązane problemy