web-dev-qa-db-ja.com

Visual Studio 2012のGoogleテスト

ユニットテストを開始しようとしています。 gtestの最新ビルドをダウンロードし、A:\gtestに抽出しました。指示に従って、gtest.slnを開きました。 Visual Studioでは、更新に同意した場合にのみslnを開くことができます。次に、ビルドしようとすると、エラーの山が表示されます:

1>------ Build started: Project: gtest, Configuration: Debug Win32 ------
1>  gtest-all.cc
1>a:\gtest\include\gtest\gtest-printers.h(550): error C2977: 'std::Tuple' : too many template arguments
1>          b:\program files (x86)\Microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::Tuple'
1>a:\gtest\include\gtest\gtest-printers.h(558): error C2977: 'std::Tuple' : too many template arguments
1>          b:\program files (x86)\Microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::Tuple'
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4017): error C2977: 'std::Tuple' : too many template arguments
1>          b:\program files (x86)\Microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::Tuple'
1>          a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4249) : see reference to class template instantiation 'testing::internal::CartesianProductGenerator9<T1,T2,T3,T4,T5,T6,T7,T8,T9>' being compiled
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4017): error C3203: 'Tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4017): error C2955: 'std::Tuple' : use of class template requires template argument list
1>          b:\program files (x86)\Microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::Tuple'
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4017): error C2955: 'testing::internal::ParamGeneratorInterface' : use of class template requires template argument list
1>          a:\gtest\include\gtest\internal\gtest-param-util.h(142) : see declaration of 'testing::internal::ParamGeneratorInterface'
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4019): error C2977: 'std::Tuple' : too many template arguments
1>          b:\program files (x86)\Microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::Tuple'
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4030): error C3203: 'Tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4030): error C2955: 'std::Tuple' : use of class template requires template argument list
1>          b:\program files (x86)\Microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::Tuple'
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4035): error C3203: 'Tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4035): error C2955: 'std::Tuple' : use of class template requires template argument list
1>          b:\program files (x86)\Microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::Tuple'
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4042): error C3203: 'Tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type
1>          a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4042) : see reference to class template instantiation 'testing::internal::CartesianProductGenerator9<T1,T2,T3,T4,T5,T6,T7,T8,T9>::Iterator' being compiled
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4042): error C2955: 'std::Tuple' : use of class template requires template argument list
1>          b:\program files (x86)\Microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::Tuple'
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4042): error C2955: 'testing::internal::ParamIteratorInterface' : use of class template requires template argument list
1>          a:\gtest\include\gtest\internal\gtest-param-util.h(69) : see declaration of 'testing::internal::ParamIteratorInterface'
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4044): error C3203: 'Tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4044): error C2955: 'std::Tuple' : use of class template requires template argument list
1>          b:\program files (x86)\Microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::Tuple'
1>          b:\program files (x86)\Microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::Tuple'
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4077): error C3203: 'Tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4077): error C2955: 'std::Tuple' : use of class template requires template argument list
1>          b:\program files (x86)\Microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::Tuple'
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4119): error C3203: 'Tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4119): error C2955: 'std::Tuple' : use of class template requires template argument list
1>          b:\program files (x86)\Microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::Tuple'
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4123): error C3203: 'Tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4123): error C2955: 'std::Tuple' : use of class template requires template argument list
1>          b:\program files (x86)\Microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::Tuple'
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4204): error C3203: 'Tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4204): error C2955: 'std::Tuple' : use of class template requires template argument list
1>          b:\program files (x86)\Microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::Tuple'
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4256): error C2977: 'std::Tuple' : too many template arguments
1>          b:\program files (x86)\Microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::Tuple'
1>          a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4505) : see reference to class template instantiation 'testing::internal::CartesianProductGenerator10<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10>' being compiled
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4256): error C3203: 'Tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4256): error C2955: 'std::Tuple' : use of class template requires template argument list
1>          b:\program files (x86)\Microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::Tuple'
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4256): error C2955: 'testing::internal::ParamGeneratorInterface' : use of class template requires template argument list
1>          a:\gtest\include\gtest\internal\gtest-param-util.h(142) : see declaration of 'testing::internal::ParamGeneratorInterface'
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4258): error C2977: 'std::Tuple' : too many template arguments
1>          b:\program files (x86)\Microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::Tuple'
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4270): error C3203: 'Tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4270): error C2955: 'std::Tuple' : use of class template requires template argument list
1>          b:\program files (x86)\Microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::Tuple'
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4275): error C3203: 'Tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4275): error C2955: 'std::Tuple' : use of class template requires template argument list
1>          b:\program files (x86)\Microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::Tuple'
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4282): error C3203: 'Tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type
1>          a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4282) : see reference to class template instantiation 'testing::internal::CartesianProductGenerator10<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10>::Iterator' being compiled
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4282): error C2955: 'std::Tuple' : use of class template requires template argument list
1>          b:\program files (x86)\Microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::Tuple'
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4282): error C2955: 'testing::internal::ParamIteratorInterface' : use of class template requires template argument list
1>          a:\gtest\include\gtest\internal\gtest-param-util.h(69) : see declaration of 'testing::internal::ParamIteratorInterface'
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4284): error C3203: 'Tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4284): error C2955: 'std::Tuple' : use of class template requires template argument list
1>          b:\program files (x86)\Microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::Tuple'
1>          b:\program files (x86)\Microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::Tuple'
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4320): error C3203: 'Tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4320): error C2955: 'std::Tuple' : use of class template requires template argument list
1>          b:\program files (x86)\Microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::Tuple'
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4366): error C3203: 'Tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4366): error C2955: 'std::Tuple' : use of class template requires template argument list
1>          b:\program files (x86)\Microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::Tuple'
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4370): error C3203: 'Tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4370): error C2955: 'std::Tuple' : use of class template requires template argument list
1>          b:\program files (x86)\Microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::Tuple'
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4456): error C3203: 'Tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4456): error C2955: 'std::Tuple' : use of class template requires template argument list
1>          b:\program files (x86)\Microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::Tuple'
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4738): error C2977: 'std::Tuple' : too many template arguments
1>          b:\program files (x86)\Microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::Tuple'
1>          a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4766) : see reference to class template instantiation 'testing::internal::CartesianProductHolder9<Generator1,Generator2,Generator3,Generator4,Generator5,Generator6,Generator7,Generator8,Generator9>' being compiled
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4738): error C3203: 'Tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4738): error C2955: 'std::Tuple' : use of class template requires template argument list
1>          b:\program files (x86)\Microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::Tuple'
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4782): error C2977: 'std::Tuple' : too many template arguments
1>          b:\program files (x86)\Microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::Tuple'
1>          a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4813) : see reference to class template instantiation 'testing::internal::CartesianProductHolder10<Generator1,Generator2,Generator3,Generator4,Generator5,Generator6,Generator7,Generator8,Generator9,Generator10>' being compiled
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4782): error C3203: 'Tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type
1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4782): error C2955: 'std::Tuple' : use of class template requires template argument list
1>          b:\program files (x86)\Microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::Tuple'
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

私は何か間違ったことをしていますか、これはVS2012の問題ですか?私はグーグルテストに執着しておらず、VSでうまく機能する場合は別のフレームワークを使用することに反対しません。gtestについて非常に良いことを聞いたばかりです。

55
user1599559

VC++ 2012は可変長テンプレートをサポートしていません(サポートしません)。その結果、その標準ライブラリの実装は、プリプロセッサで生成されたオーバーロードと特殊化を使用してそれらを偽造しようとします。 このブログ記事 notesのように、偽の可変長テンプレートパラメータの数はデフォルトで5に設定されています。問題は、gtestがstd::Tuple<>最大10個のテンプレート引数。

ブログの投稿で言及しているように、_VARIADIC_MAX最大10個のパラメーターをサポートするプロジェクト全体のマクロ。おそらくプロジェクトの プリプロセッサ定義 設定によってこれを行いたいと思うでしょうが、重要なことは、すべてのTUがstdlibヘッダーを含める前に必ず定義することです(直接または間接)。

78
ildjarn

_VARIADIC_MAXマクロを使用してVS2012 Tuple実装を変更するのではなく、gtestプロジェクトとgtestヘッダーを含むプロジェクトで次の2つのマクロを定義することでこの問題を解決しました。

GTEST_HAS_TR1_Tuple=0
GTEST_USE_OWN_TR1_Tuple=1

GTEST_HAS_TR1_Tupleを0に設定すると、gtestがSTLヘッダーからTupleクラスを使用しようとするのを防ぎ、GTEST_USE_OWN_TR1_Tupleを1に設定すると、gtestがTupleサポートを必要とする機能を省略せずに独自のTuple実装を使用するように指示します。私は個人的に、このオプションをSTL実装の調整よりも好みました。このソリューションは、同様の問題を抱えている他のコンパイラーでも動作するはずです。

8
Roger Sanders

これはバージョンr675で修正されています。 https://code.google.com/p/googletest/source/detail?r=675 を参照してください

6
Corey Kosak

また、最新バージョンを入手するまで、GTEST_USE_OWN_TR1_Tuple=0プリプロセッサ定義に。

1
Brad W