From 479ba8e76d90f7c66b5c843eb890687c411d07fb Mon Sep 17 00:00:00 2001 From: Pavel Krajcevski Date: Wed, 12 Mar 2014 02:43:09 -0400 Subject: [PATCH] Fix a bunch of MSVC compiler warnings and errors. Most notably, we need to actually fix a bug in MSVC that doesn't know how to properly instantiate enums in partial template specialization. There are more details outlined here: http://stackoverflow.com/questions/15466594/why-does-msvc-fail-to-compile-this-template-function The fix in this commit closes #10 Also in this commit is a hacky way to allow GL defines. Apparently "LoadImage" is defined as a macro even with WIN32_LEAN_AND_MEAN. This means that we have to #undef the code that includes it, meaning that we also need to make sure not to actually mix GLDefines.h with any file that needs to use the functions from Windows.h --- Base/include/MatrixSquare.h | 2 +- Base/include/VectorBase.h | 5 +++-- Base/test/TestMatrix.cpp | 4 ++-- Base/test/TestVector.cpp | 4 ++-- CLTool/src/compare.cpp | 5 ----- IO/src/GLDefines.h | 5 +++++ 6 files changed, 13 insertions(+), 12 deletions(-) diff --git a/Base/include/MatrixSquare.h b/Base/include/MatrixSquare.h index df887b0..99edeca 100644 --- a/Base/include/MatrixSquare.h +++ b/Base/include/MatrixSquare.h @@ -73,7 +73,7 @@ namespace FasTC { // principal eigenvector. However, that may be due to // poor initialization of the random vector, so rerandomize // and try again. - const float newBlen = newB.Length(); + const T newBlen = newB.Length(); if(newBlen < 1e-10) { if(badEigenValue) { eigVec = b; diff --git a/Base/include/VectorBase.h b/Base/include/VectorBase.h index df64c1d..5b04112 100644 --- a/Base/include/VectorBase.h +++ b/Base/include/VectorBase.h @@ -183,9 +183,10 @@ namespace FasTC { return a; } + // !WTF! MSVC bug with enums in template parameters =( template< - EVectorType kVectorTypeOne, - EVectorType kVectorTypeTwo, + /* EVectorType */unsigned kVectorTypeOne, + /* EVectorType */unsigned kVectorTypeTwo, typename TypeOne, typename TypeTwo> class MultSwitch { diff --git a/Base/test/TestMatrix.cpp b/Base/test/TestMatrix.cpp index c5bd66c..6ccf03c 100644 --- a/Base/test/TestMatrix.cpp +++ b/Base/test/TestMatrix.cpp @@ -53,7 +53,7 @@ #include "gtest/gtest.h" #include "MatrixBase.h" -static const float kEpsilon = 1e-6; +static const float kEpsilon = 1e-6f; TEST(MatrixBase, Constructors) { FasTC::MatrixBase m3f; @@ -123,7 +123,7 @@ TEST(MatrixBase, PointerConversion) { } TEST(MatrixBase, CastVector) { - srand(time(NULL)); + srand(static_cast(time(NULL))); FasTC::MatrixBase v3f; for(int i = 0; i < 6; i++) { diff --git a/Base/test/TestVector.cpp b/Base/test/TestVector.cpp index bafec99..976dae5 100644 --- a/Base/test/TestVector.cpp +++ b/Base/test/TestVector.cpp @@ -53,7 +53,7 @@ #include "gtest/gtest.h" #include "VectorBase.h" -static const float kEpsilon = 1e-6; +static const float kEpsilon = 1e-6f; TEST(VectorBase, Constructors) { FasTC::VectorBase v3f; @@ -173,7 +173,7 @@ TEST(VectorBase, Normalization) { EXPECT_EQ(v2u[0], 1); EXPECT_EQ(v2u[1], 1); - const float sqrt2 = sqrt(2)/2.0f; + const double sqrt2 = sqrt(2)/2.0f; for(int i = 2; i < 10; i++) { v2f[0] = static_cast(i); v2f[1] = static_cast(i); diff --git a/CLTool/src/compare.cpp b/CLTool/src/compare.cpp index c9982c4..93e1a8d 100644 --- a/CLTool/src/compare.cpp +++ b/CLTool/src/compare.cpp @@ -59,12 +59,7 @@ #include "TexComp.h" #include "ThreadSafeStreambuf.h" -#ifdef _MSC_VER -int _tmain(int argc, _TCHAR* argv[]) { -#else int main(int argc, char **argv) { -#endif - if(argc != 3) { fprintf(stderr, "Usage: compare \n"); return 1; diff --git a/IO/src/GLDefines.h b/IO/src/GLDefines.h index 5c086d2..6c9a3fe 100644 --- a/IO/src/GLDefines.h +++ b/IO/src/GLDefines.h @@ -57,6 +57,11 @@ # ifdef __APPLE__ # include # else +# ifdef _MSC_VER +# define WIN32_LEAN_AND_MEAN +# include "Windows.h" +# undef LoadImage +# endif # include # endif #endif