GCC 4.8にアップグレードしたばかりで、いくつかの可変テンプレートコードが正しくコンパイルされなくなりました。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のための間違ったバージョンをコメントアウトする場合):私は、以下の最小限の例を作成しました。
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これは私にはバグのように見える