2013-03-28 4 views
23

방금 ​​GCC 4.8로 업그레이드했고 일부 가변적 인 템플릿 코드가 더 이상 올바르게 컴파일되지 않습니다.GCC 4.8이 variadic 템플릿 매개 변수 팩을 뒤집습니다.

#include <tuple> 
#include <iostream> 

template <class T, class ... OtherT> 
void something(std::tuple<T, OtherT...> & tup) 
{ 
    std::cout << std::get<1>(tup) << std::endl; 
} 

int main() 
{ 
    std::tuple<int, char, bool> myTuple(3, 'a', true); 

    // Compiles OK in GCC 4.6.3 but NOT 4.8 
    something<int, char, bool>(myTuple); 

    // Compiles OK in GCC 4.8 but NOT 4.6.3 
    something<int, bool, char>(myTuple); 

    return 0; 
} 

이의 출력이 될 것입니다 'A'(GCC 4.6.3/4.8에 대한 잘못된 버전을 주석 경우) : 나는 아래 최소한의 예를 만들었습니다.

GCC 4.6.3에 의해 생성 된 오류 :

./test.cpp: In function ‘int main()’: 
./test.cpp:18:39: error: no matching function for call to ‘something(std::tuple<int, char, bool>&)’ 
./test.cpp:18:39: note: candidate is: 
./test.cpp:5:6: note: template<class T, class ... OtherT> void something(std::tuple<_Head, _Tail ...>&) 

GCC 4.8에 의해 생성 된 오류 : 팽창시 GCC 4.8에서 가변 템플릿 유형이 반전처럼

./test.cpp: In function ‘int main()’: 
./test.cpp:15:39: error: no matching function for call to ‘something(std::tuple<int, char, bool>&)’ 
    something<int, char, bool>(myTuple); 
            ^
./test.cpp:15:39: note: candidate is: 
./test.cpp:5:6: note: template<class T, class ... OtherT> void something(std::tuple<_El0, _El ...>&) 
void something(std::tuple<T, OtherT...> & tup) 
    ^
./test.cpp:5:6: note: template argument deduction/substitution failed: 
./test.cpp:15:39: note: mismatched types ‘bool’ and ‘char’ 
    something<int, char, bool>(myTuple); 

것 같다 이상하게도 그들은 출력에 의해 증명 된 것처럼 "정말로"되돌아 가지는 않는다. 주문과 상관없이 'a'가 될 것이다. Clang 3.3은 GCC 4.6.3 출력에 동의합니다.

GCC 4.8 또는 다른 버그입니까?

편집 : 여기 GCC에 버그 리포트를 추가 : http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56774이 나에게 벌레처럼 보이는

답변

15

이, GCC 4.8.0과 GCC 4.7.2이 영향을받을 것으로 보인다. Clang 3.2와 GCC 4.6.3은 something에 대한 첫 번째 호출이 정확하다는 것에 동의하며, 나는 GCC 4.7.2+가 두 번째 호출을 받아 들일 수있는 방법으로 생각할 수 없다는 것에 정말로 실패한다.

나는 다음과 같이 말하고 싶다. GCC에 버그를보고한다.


업데이트

: 난 그냥 그들을 도울하고 순수한 컴파일러 버그와 std::tuple와는 아무 상관이 없다는 것을 증명하기 위해, GCC의 버그 보고서에 최소한의 예를 추가했습니다. 여기에 감소 된 코드는 다음과 같습니다

template<typename...> struct X {}; 

template< typename T, typename... Ts > 
void f(X< T, Ts... >&) {} 

int main() 
{ 
    X< int, bool, char > t; 
    f< int, char, bool >(t); 
} 

업데이트 2 : 그것은 지금 GCC 4.7.3, GCC 4.8.1 고정 것 및 GCC 4.9 - GCC의 팀에 찬사를 미친 듯이 빠른 수정을 위해!

관련 문제