![](/img/trans.png)
[英]Clang vs GCC - Variadic template parameter pack followed by parameter with default value works in GCC 4.8 but not Clang 3.5
[英]GCC 4.8 is reversing variadic template parameter pack
我剛剛升級到GCC 4.8,一些可變參數模板代碼不再正確編譯。 我在下面創建了一個最小的例子:
#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;
}
這個輸出將是(如果注釋掉GCC 4.6.3 / 4.8的錯誤版本)'a'。
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產生的錯誤是:
./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 );
看起來在GCC 4.8中,可變參數模板類型在擴展時會被反轉,但奇怪的是它們並沒有像輸出所證明的那樣“真正地”反轉 - 無論順序如何,它都是'a'。 Clang 3.3同意GCC 4.6.3輸出。
這是GCC 4.8中的錯誤還是其他什么?
編輯:在這里向GCC添加了一個錯誤報告: http : //gcc.gnu.org/bugzilla/show_bug.cgi? id = 56774
這看起來像是一個bug,GCC 4.8.0和GCC 4.7.2似乎受到了影響。 Clang 3.2和GCC 4.6.3同意第一次調用something
是正確的,我真的沒有看到GCC 4.7.2+如何將第二次調用視為可接受。
我會說:報告一個針對GCC的錯誤。
更新:我在GCC錯誤報告中添加了一個簡約示例,只是為了幫助他們並證明它是一個純粹的編譯器錯誤,與std::tuple
無關。 這是減少的代碼:
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團隊的一次非常快速的修復!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.