Browse Source

Dealing with MSVC warnings a little bit more elegantly

Ignacio Fraga 6 years ago
parent
commit
3bb73fbdd7

+ 14 - 1
cmake/libigl.cmake

@@ -148,7 +148,20 @@ function(compile_igl_module module_dir)
     endif()
     add_library(${module_libname} STATIC ${SOURCES_IGL_${module_name}} ${ARGN})
     if(MSVC)
-      target_compile_options(${module_libname} PRIVATE /w) # disable all warnings (not ideal but...)
+      # Silencing some compile warnings
+      target_compile_options(${module_libname} PRIVATE 
+        # Type conversion warnings. These can be fixed with some effort and possibly more verbose code.
+        /wd4267 # conversion from 'size_t' to 'type', possible loss of data
+        /wd4244 # conversion from 'type1' to 'type2', possible loss of data
+        /wd4018 # signed/unsigned mismatch
+        /wd4305 # truncation from 'double' to 'float'
+        # This one is from template instantiations generated by autoexplicit.sh:
+        /wd4667 # no function template defined that matches forced instantiation ()
+        # This one is easy to fix, just need to switch to safe version of C functions
+        /wd4996 # this function or variable may be unsafe
+        # This one is when using bools in adjacency matrices
+        /wd4804 #'+=': unsafe use of type 'bool' in operation
+      )
     else()
       #target_compile_options(${module_libname} PRIVATE -w) # disable all warnings (not ideal but...)
     endif()

+ 2 - 2
include/igl/EPS.h

@@ -13,8 +13,8 @@ namespace igl
   // Define a standard value for double epsilon
   const double DOUBLE_EPS    = 1.0e-14;
   const double DOUBLE_EPS_SQ = 1.0e-28;
-  const float FLOAT_EPS    = 1.0e-7;
-  const float FLOAT_EPS_SQ = 1.0e-14;
+  const float FLOAT_EPS    = 1.0e-7f;
+  const float FLOAT_EPS_SQ = 1.0e-14f;
   // Function returning EPS for corresponding type
   template <typename S_type> IGL_INLINE S_type EPS();
   template <typename S_type> IGL_INLINE S_type EPS_SQ();

+ 1 - 1
include/igl/bounding_box.cpp

@@ -30,7 +30,7 @@ IGL_INLINE void igl::bounding_box(
   const auto & minV = V.colwise().minCoeff().array()-pad;
   const auto & maxV = V.colwise().maxCoeff().array()+pad;
   // 2^n vertices
-  BV.resize((1<<dim),dim);
+  BV.resize((1ull<<dim),dim);
 
   // Recursive lambda to generate all 2^n combinations
   const std::function<void(const int,const int,int*,int)> combos =

+ 2 - 2
include/igl/copyleft/quadprog.cpp

@@ -139,7 +139,7 @@ IGL_INLINE bool igl::copyleft::quadprog(
 #ifdef TRACE_SOLVER
     std::cerr << "Add constraint " << iq << '/';
 #endif
-    int i, j, k;
+    int j, k;
     double cc, ss, h, t1, t2, xny;
     
     /* we have to find the Givens rotation which will reduce the element
@@ -284,7 +284,7 @@ IGL_INLINE bool igl::copyleft::quadprog(
     }
   };
 
-  int i, j, k, l; /* indices */
+  int i, k, l; /* indices */
   int ip, me, mi;
   int n=g0.size();  int p=ce0.size();  int m=ci0.size();  
   MatrixXd R(G.rows(),G.cols()), J(G.rows(),G.cols());

+ 1 - 1
include/igl/jet.cpp

@@ -44,7 +44,7 @@ IGL_INLINE void igl::jet(const T x_in, T & r, T & g, T & b)
     b = (bone - (x - 3. / 8.) / (5. / 8. - 3. / 8.));
   } else if (x<7. / 8.)
   {
-    r = rone;
+    r = T(rone);
     g = (gone - (x - 5. / 8.) / (7. / 8. - 5. / 8.));
     b = 0;
   } else

+ 1 - 0
include/igl/launch_medit.cpp

@@ -56,6 +56,7 @@ IGL_INLINE int igl::launch_medit(
     return system(command.str().c_str());
   }catch(int e)
   {
+    (void)e;
     cerr<<"^"<<__FUNCTION__<<": Calling to medit crashed..."<<endl;
     return -1;
   }

+ 10 - 0
tests/CMakeLists.txt

@@ -32,6 +32,16 @@ target_include_directories(libigl_tests PUBLIC ${CMAKE_CURRENT_LIST_DIR})
 set(DATA_DIR "${CMAKE_CURRENT_SOURCE_DIR}/data/")
 target_compile_definitions(libigl_tests PUBLIC -DLIBIGL_DATA_DIR="${IGL_TEST_DATA}")
 
+# Silencing some compile warnings
+if(MSVC)
+  target_compile_options(libigl_tests PRIVATE
+    # Type conversion warnings. These can be fixed with some effort and possibly more verbose code.
+    /wd4267 # conversion from 'size_t' to 'type', possible loss of data
+    /wd4244 # conversion from 'type1' to 'type2', possible loss of data
+    /wd4018 # signed/unsigned mismatch
+    /wd4305 # truncation from 'double' to 'float'
+  )
+endif(MSVC)
 
 # Process code in each subdirectories: add in decreasing order of complexity
 # (last added will run first and those should be the fastest tests)

+ 1 - 1
tests/include/igl/qslim.cpp

@@ -19,7 +19,7 @@ TEST_CASE("qslim: cylinder", "[igl]")
   Eigen::VectorXi I,J;
   qslim(V,F,2*axis_devisions,U,G,I,J);
   REQUIRE (U.rows() == axis_devisions*2);
-  double l,u;
+  //double l,u;
   igl::writePLY("qslim-cylinder-vf.ply",V,F);
   igl::writePLY("qslim-cylinder-ug.ply",U,G);
   const auto & hausdorff_lower_bound = [](