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