From 37f7f76d87bb5b0fe8a56775917718b2e86649d3 Mon Sep 17 00:00:00 2001
From: Jeremie Deray <todo@stuff.com>
Date: Sat, 5 Aug 2017 11:48:37 +0200
Subject: [PATCH] fix gcc 5+ compilation -Werror=unused-variable

---
 src/factory.h                       | 20 +++++++++++++++++++-
 src/frame_base.cpp                  |  6 +++---
 src/frame_imu.cpp                   |  2 +-
 src/landmark_polyline_2D.cpp        |  2 +-
 src/processor_factory.h             |  2 +-
 src/sensor_factory.h                |  2 +-
 src/yaml/processor_image_yaml.cpp   |  4 ++--
 src/yaml/processor_imu_yaml.cpp     |  2 +-
 src/yaml/processor_odom_3D_yaml.cpp |  2 +-
 src/yaml/sensor_camera_yaml.cpp     |  2 +-
 src/yaml/sensor_imu_yaml.cpp        |  2 +-
 src/yaml/sensor_laser_2D_yaml.cpp   |  2 +-
 src/yaml/sensor_odom_3D_yaml.cpp    |  2 +-
 13 files changed, 34 insertions(+), 16 deletions(-)

diff --git a/src/factory.h b/src/factory.h
index 6a754ba74..cec1b2d09 100644
--- a/src/factory.h
+++ b/src/factory.h
@@ -355,10 +355,28 @@ inline std::string FrameFactory::getClass()
 {
     return "FrameFactory";
 }
+
+//#define UNUSED(x) (void)x;
+//#define UNUSED(x) (void)(sizeof((x), 0));
+
+#ifdef __GNUC__
+    #define WOLF_UNUSED __attribute__((used))
+#elif defined _MSC_VER
+    #pragma warning(disable: Cxxxxx)
+    #define WOLF_UNUSED
+#elif defined(__LCLINT__)
+# define WOLF_UNUSED /*@unused@*/
+#elif defined(__cplusplus)
+# define WOLF_UNUSED
+#else
+# define UNUSED(x) x
+#endif
+
 #define WOLF_REGISTER_FRAME(FrameType, FrameName) \
-  namespace{ const bool FrameName##Registered = \
+  namespace{ const bool WOLF_UNUSED FrameName##Registered = \
     FrameFactory::get().registerCreator(FrameType, FrameName::create); }\
 
+
 } /* namespace wolf */
 
 #endif /* FACTORY_H_ */
diff --git a/src/frame_base.cpp b/src/frame_base.cpp
index 5576b8aac..0ba15c744 100644
--- a/src/frame_base.cpp
+++ b/src/frame_base.cpp
@@ -301,7 +301,7 @@ FrameBasePtr FrameBase::create_POV_3D(const FrameType & _tp,
 #include "factory.h"
 namespace wolf
 {
-namespace{ const bool Frame_PO_2D_Registered  = FrameFactory::get().registerCreator("PO 2D",  FrameBase::create_PO_2D ); }
-namespace{ const bool Frame_PO_3D_Registered  = FrameFactory::get().registerCreator("PO 3D",  FrameBase::create_PO_3D ); }
-namespace{ const bool Frame_POV_3D_Registered = FrameFactory::get().registerCreator("POV 3D", FrameBase::create_POV_3D); }
+namespace{ const bool WOLF_UNUSED Frame_PO_2D_Registered  = FrameFactory::get().registerCreator("PO 2D",  FrameBase::create_PO_2D ); }
+namespace{ const bool WOLF_UNUSED Frame_PO_3D_Registered  = FrameFactory::get().registerCreator("PO 3D",  FrameBase::create_PO_3D ); }
+namespace{ const bool WOLF_UNUSED Frame_POV_3D_Registered = FrameFactory::get().registerCreator("POV 3D", FrameBase::create_POV_3D); }
 } // namespace wolf
diff --git a/src/frame_imu.cpp b/src/frame_imu.cpp
index b1897f083..0b2f52736 100644
--- a/src/frame_imu.cpp
+++ b/src/frame_imu.cpp
@@ -43,5 +43,5 @@ FrameBasePtr FrameIMU::create(const FrameType & _tp,
 namespace wolf
 {
 WOLF_REGISTER_FRAME("IMU", FrameIMU);
-namespace{ const bool Frame_PQVBB_3D_Registered = FrameFactory::get().registerCreator("PQVBB 3D", FrameIMU::create); } // alternate name possible
+namespace{ const bool WOLF_UNUSED Frame_PQVBB_3D_Registered = FrameFactory::get().registerCreator("PQVBB 3D", FrameIMU::create); } // alternate name possible
 } // namespace wolf
diff --git a/src/landmark_polyline_2D.cpp b/src/landmark_polyline_2D.cpp
index 71111ff6a..951990a86 100644
--- a/src/landmark_polyline_2D.cpp
+++ b/src/landmark_polyline_2D.cpp
@@ -386,7 +386,7 @@ YAML::Node LandmarkPolyline2D::saveToYaml() const
 // Register landmark creator
 namespace
 {
-const bool registered_lmk_polyline_2D = LandmarkFactory::get().registerCreator("POLYLINE 2D", LandmarkPolyline2D::create);
+const bool WOLF_UNUSED registered_lmk_polyline_2D = LandmarkFactory::get().registerCreator("POLYLINE 2D", LandmarkPolyline2D::create);
 }
 
 } /* namespace wolf */
diff --git a/src/processor_factory.h b/src/processor_factory.h
index a5ba73118..d558d458e 100644
--- a/src/processor_factory.h
+++ b/src/processor_factory.h
@@ -177,7 +177,7 @@ inline std::string ProcessorFactory::getClass()
 
 
 #define WOLF_REGISTER_PROCESSOR(ProcessorType, ProcessorName) \
-  namespace{ const bool ProcessorName##Registered = \
+  namespace{ const bool WOLF_UNUSED ProcessorName##Registered = \
     ProcessorFactory::get().registerCreator(ProcessorType, ProcessorName::create); }\
 
 } /* namespace wolf */
diff --git a/src/sensor_factory.h b/src/sensor_factory.h
index 0f503e423..3e7e1aabc 100644
--- a/src/sensor_factory.h
+++ b/src/sensor_factory.h
@@ -219,7 +219,7 @@ inline std::string SensorFactory::getClass()
 }
 
 #define WOLF_REGISTER_SENSOR(SensorType, SensorName) \
-  namespace{ const bool SensorName##Registered = \
+  namespace{ const bool WOLF_UNUSED SensorName##Registered = \
     SensorFactory::get().registerCreator(SensorType, SensorName::create); }\
 
 } /* namespace wolf */
diff --git a/src/yaml/processor_image_yaml.cpp b/src/yaml/processor_image_yaml.cpp
index 9a5e34487..e921ce10c 100644
--- a/src/yaml/processor_image_yaml.cpp
+++ b/src/yaml/processor_image_yaml.cpp
@@ -84,8 +84,8 @@ static ProcessorParamsBasePtr createProcessorParamsImage(const std::string & _fi
 }
 
 // Register in the SensorFactory
-const bool registered_prc_image_feature_par = ProcessorParamsFactory::get().registerCreator("IMAGE FEATURE", createProcessorParamsImage);
-const bool registered_prc_image_landmark_par = ProcessorParamsFactory::get().registerCreator("IMAGE LANDMARK", createProcessorParamsImage);
+const bool WOLF_UNUSED registered_prc_image_feature_par = ProcessorParamsFactory::get().registerCreator("IMAGE FEATURE", createProcessorParamsImage);
+const bool WOLF_UNUSED registered_prc_image_landmark_par = ProcessorParamsFactory::get().registerCreator("IMAGE LANDMARK", createProcessorParamsImage);
 
 
 }
diff --git a/src/yaml/processor_imu_yaml.cpp b/src/yaml/processor_imu_yaml.cpp
index 3301e52ff..8ac801dd2 100644
--- a/src/yaml/processor_imu_yaml.cpp
+++ b/src/yaml/processor_imu_yaml.cpp
@@ -52,7 +52,7 @@ static ProcessorParamsBasePtr createProcessorIMUParams(const std::string & _file
 }
 
 // Register in the SensorFactory
-const bool registered_prc_odom_3D = ProcessorParamsFactory::get().registerCreator("IMU", createProcessorIMUParams);
+const bool WOLF_UNUSED registered_prc_odom_3D = ProcessorParamsFactory::get().registerCreator("IMU", createProcessorIMUParams);
 
 } // namespace [unnamed]
 
diff --git a/src/yaml/processor_odom_3D_yaml.cpp b/src/yaml/processor_odom_3D_yaml.cpp
index 9a20f5c7c..a8fbce599 100644
--- a/src/yaml/processor_odom_3D_yaml.cpp
+++ b/src/yaml/processor_odom_3D_yaml.cpp
@@ -51,7 +51,7 @@ static ProcessorParamsBasePtr createProcessorOdom3DParams(const std::string & _f
 }
 
 // Register in the SensorFactory
-const bool registered_prc_odom_3D = ProcessorParamsFactory::get().registerCreator("ODOM 3D", createProcessorOdom3DParams);
+const bool WOLF_UNUSED registered_prc_odom_3D = ProcessorParamsFactory::get().registerCreator("ODOM 3D", createProcessorOdom3DParams);
 
 } // namespace [unnamed]
 
diff --git a/src/yaml/sensor_camera_yaml.cpp b/src/yaml/sensor_camera_yaml.cpp
index a2feb6fe4..c3c94d6b4 100644
--- a/src/yaml/sensor_camera_yaml.cpp
+++ b/src/yaml/sensor_camera_yaml.cpp
@@ -91,7 +91,7 @@ static IntrinsicsBasePtr createIntrinsicsCamera(const std::string & _filename_do
 }
 
 // Register in the SensorFactory
-const bool registered_camera_intr = IntrinsicsFactory::get().registerCreator("CAMERA", createIntrinsicsCamera);
+const bool WOLF_UNUSED registered_camera_intr = IntrinsicsFactory::get().registerCreator("CAMERA", createIntrinsicsCamera);
 
 } // namespace [unnamed]
 
diff --git a/src/yaml/sensor_imu_yaml.cpp b/src/yaml/sensor_imu_yaml.cpp
index d7ff11195..babce6140 100644
--- a/src/yaml/sensor_imu_yaml.cpp
+++ b/src/yaml/sensor_imu_yaml.cpp
@@ -53,7 +53,7 @@ static IntrinsicsBasePtr createIntrinsicsIMU(const std::string & _filename_dot_y
 }
 
 // Register in the SensorFactory
-const bool registered_imu_intr = IntrinsicsFactory::get().registerCreator("IMU", createIntrinsicsIMU);
+const bool WOLF_UNUSED registered_imu_intr = IntrinsicsFactory::get().registerCreator("IMU", createIntrinsicsIMU);
 
 } // namespace [unnamed]
 
diff --git a/src/yaml/sensor_laser_2D_yaml.cpp b/src/yaml/sensor_laser_2D_yaml.cpp
index c703d7305..160386e6e 100644
--- a/src/yaml/sensor_laser_2D_yaml.cpp
+++ b/src/yaml/sensor_laser_2D_yaml.cpp
@@ -31,7 +31,7 @@ IntrinsicsBasePtr createIntrinsicsLaser2D(const std::string& _filename_dot_yaml)
 
 
 // register into factory
-const bool registered_laser_params = IntrinsicsFactory::get().registerCreator("LASER 2D", createIntrinsicsLaser2D);
+const bool WOLF_UNUSED registered_laser_params = IntrinsicsFactory::get().registerCreator("LASER 2D", createIntrinsicsLaser2D);
 
 } // namespace [void]
 } // namespace wolf
diff --git a/src/yaml/sensor_odom_3D_yaml.cpp b/src/yaml/sensor_odom_3D_yaml.cpp
index 5501666e7..a6012aeef 100644
--- a/src/yaml/sensor_odom_3D_yaml.cpp
+++ b/src/yaml/sensor_odom_3D_yaml.cpp
@@ -51,7 +51,7 @@ static IntrinsicsBasePtr createIntrinsicsOdom3D(const std::string & _filename_do
 }
 
 // Register in the SensorFactory
-const bool registered_odom_3D_intr = IntrinsicsFactory::get().registerCreator("ODOM 3D", createIntrinsicsOdom3D);
+const bool WOLF_UNUSED registered_odom_3D_intr = IntrinsicsFactory::get().registerCreator("ODOM 3D", createIntrinsicsOdom3D);
 
 } // namespace [unnamed]
 
-- 
GitLab