From cc7c7f2b245808d715509b5cc19dfe1cedb172a5 Mon Sep 17 00:00:00 2001
From: Dmitri Naumov <github@naumov.de>
Date: Fri, 17 Jun 2016 03:01:17 +0000
Subject: [PATCH] Protect expressions in macros with parentheses.

---
 MathLib/LinAlg/Eigen/EigenOption.cpp          | 4 ++--
 MeshLib/MeshEnums.cpp                         | 2 +-
 NumLib/DOF/GlobalMatrixProviders.cpp          | 4 ++--
 Tests/MeshLib/TestCoordinatesMappingLocal.cpp | 6 +++---
 4 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/MathLib/LinAlg/Eigen/EigenOption.cpp b/MathLib/LinAlg/Eigen/EigenOption.cpp
index 5e615e78516..36bc4a671ff 100644
--- a/MathLib/LinAlg/Eigen/EigenOption.cpp
+++ b/MathLib/LinAlg/Eigen/EigenOption.cpp
@@ -23,7 +23,7 @@ EigenOption::EigenOption()
 EigenOption::SolverType EigenOption::getSolverType(const std::string &solver_name)
 {
 #define RETURN_SOLVER_ENUM_IF_SAME_STRING(str, TypeName) \
-    if (#TypeName==str) return SolverType::TypeName;
+    if (#TypeName==(str)) return SolverType::TypeName;
 
     RETURN_SOLVER_ENUM_IF_SAME_STRING(solver_name, CG);
     RETURN_SOLVER_ENUM_IF_SAME_STRING(solver_name, BiCGSTAB);
@@ -36,7 +36,7 @@ EigenOption::SolverType EigenOption::getSolverType(const std::string &solver_nam
 EigenOption::PreconType EigenOption::getPreconType(const std::string &precon_name)
 {
 #define RETURN_PRECOM_ENUM_IF_SAME_STRING(str, TypeName) \
-    if (#TypeName==str) return PreconType::TypeName;
+    if (#TypeName==(str)) return PreconType::TypeName;
 
     RETURN_PRECOM_ENUM_IF_SAME_STRING(precon_name, NONE);
     RETURN_PRECOM_ENUM_IF_SAME_STRING(precon_name, DIAGONAL);
diff --git a/MeshLib/MeshEnums.cpp b/MeshLib/MeshEnums.cpp
index 1321b09f1c1..0f9a87bd180 100644
--- a/MeshLib/MeshEnums.cpp
+++ b/MeshLib/MeshEnums.cpp
@@ -104,7 +104,7 @@ std::vector<std::string> getMeshElemTypeStringsShort()
 const std::string CellType2String(const CellType t)
 {
 #define RETURN_CELL_TYPE_STR(t, type)\
-    if (t == CellType::type)\
+    if ((t) == CellType::type)\
         return #type;
 
     RETURN_CELL_TYPE_STR(t, POINT1);
diff --git a/NumLib/DOF/GlobalMatrixProviders.cpp b/NumLib/DOF/GlobalMatrixProviders.cpp
index 4d42f1b5d5d..fc4872257f6 100644
--- a/NumLib/DOF/GlobalMatrixProviders.cpp
+++ b/NumLib/DOF/GlobalMatrixProviders.cpp
@@ -23,10 +23,10 @@
     \
     namespace MathLib { \
     template<> \
-    VectorProvider<VEC>& GlobalVectorProvider<VEC>::provider = *VARNAME; \
+    VectorProvider<VEC>& GlobalVectorProvider<VEC>::provider = *(VARNAME); \
     \
     template<> \
-    MatrixProvider<MAT>& GlobalMatrixProvider<MAT>::provider = *VARNAME; \
+    MatrixProvider<MAT>& GlobalMatrixProvider<MAT>::provider = *(VARNAME); \
     }
 
 
diff --git a/Tests/MeshLib/TestCoordinatesMappingLocal.cpp b/Tests/MeshLib/TestCoordinatesMappingLocal.cpp
index aec1558bbd4..bc028b1a5a8 100644
--- a/Tests/MeshLib/TestCoordinatesMappingLocal.cpp
+++ b/Tests/MeshLib/TestCoordinatesMappingLocal.cpp
@@ -142,10 +142,10 @@ void debugOutput(MeshLib::Element *ele, MeshLib::ElementCoordinatesMappingLocal
 
 // check if using the rotation matrix results in the original coordinates
 #define CHECK_COORDS(ele, mapping)\
-    for (unsigned ii=0; ii<ele->getNumberOfNodes(); ii++) {\
-        MathLib::Point3d global(matR*mapping.getMappedCoordinates(ii));\
+    for (unsigned ii=0; ii<(ele)->getNumberOfNodes(); ii++) {\
+        MathLib::Point3d global(matR*(mapping).getMappedCoordinates(ii));\
         const double eps(std::numeric_limits<double>::epsilon());\
-        ASSERT_ARRAY_NEAR(&(*ele->getNode(ii))[0], global.getCoords(), 3u, eps);\
+        ASSERT_ARRAY_NEAR(&(*(ele)->getNode(ii))[0], global.getCoords(), 3u, eps);\
     }
 
 } //namespace
-- 
GitLab