diff --git a/CMakeLists.txt b/CMakeLists.txt index 4152ecc34..7deaeb5ba 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -614,6 +614,12 @@ IF (MSVC) SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /ignore:4049") ENDIF (MSVC) +# GCC is not strict enough by default, so enable most of the warnings. +IF ("${UNIX}") + SET(CMAKE_CXX_FLAGS + "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wno-sign-compare -Wno-unused") +ENDIF ("${UNIX}") + ADD_SUBDIRECTORY(internal/ceres) OPTION(BUILD_DOCUMENTATION diff --git a/include/ceres/internal/manual_constructor.h b/include/ceres/internal/manual_constructor.h index 174d35ee2..7ea723d2a 100644 --- a/include/ceres/internal/manual_constructor.h +++ b/include/ceres/internal/manual_constructor.h @@ -110,56 +110,61 @@ class ManualConstructor { inline Type& operator*() { return *get(); } inline const Type& operator*() const { return *get(); } + // This is needed to get around the strict aliasing warning GCC generates. + inline void* space() { + return reinterpret_cast(space_); + } + // You can pass up to four constructor arguments as arguments of Init(). inline void Init() { - new(space_) Type; + new(space()) Type; } template inline void Init(const T1& p1) { - new(space_) Type(p1); + new(space()) Type(p1); } template inline void Init(const T1& p1, const T2& p2) { - new(space_) Type(p1, p2); + new(space()) Type(p1, p2); } template inline void Init(const T1& p1, const T2& p2, const T3& p3) { - new(space_) Type(p1, p2, p3); + new(space()) Type(p1, p2, p3); } template inline void Init(const T1& p1, const T2& p2, const T3& p3, const T4& p4) { - new(space_) Type(p1, p2, p3, p4); + new(space()) Type(p1, p2, p3, p4); } template inline void Init(const T1& p1, const T2& p2, const T3& p3, const T4& p4, const T5& p5) { - new(space_) Type(p1, p2, p3, p4, p5); + new(space()) Type(p1, p2, p3, p4, p5); } template inline void Init(const T1& p1, const T2& p2, const T3& p3, const T4& p4, const T5& p5, const T6& p6) { - new(space_) Type(p1, p2, p3, p4, p5, p6); + new(space()) Type(p1, p2, p3, p4, p5, p6); } template inline void Init(const T1& p1, const T2& p2, const T3& p3, const T4& p4, const T5& p5, const T6& p6, const T7& p7) { - new(space_) Type(p1, p2, p3, p4, p5, p6, p7); + new(space()) Type(p1, p2, p3, p4, p5, p6, p7); } template inline void Init(const T1& p1, const T2& p2, const T3& p3, const T4& p4, const T5& p5, const T6& p6, const T7& p7, const T8& p8) { - new(space_) Type(p1, p2, p3, p4, p5, p6, p7, p8); + new(space()) Type(p1, p2, p3, p4, p5, p6, p7, p8); } template