diff --git a/CMakeLists.txt b/CMakeLists.txt index e8396dd17b..200de4e8ca 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,6 +15,12 @@ endif() include (CheckCXXCompilerFlag) +if(NOT MSVC) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wunused-variable") +else() + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /w14101") +endif() + CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11) CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X) if(COMPILER_SUPPORTS_CXX11) diff --git a/include/openbabel/base.h b/include/openbabel/base.h index b9cbea88de..8b4be4c482 100644 --- a/include/openbabel/base.h +++ b/include/openbabel/base.h @@ -28,15 +28,6 @@ GNU General Public License for more details. #include #include -#ifdef UNUSED -#elif (__GNUC__ == 4) -# define UNUSED(x) UNUSED_ ## x __attribute__((unused)) -#elif defined(__LCLINT__) -# define UNUSED(x) /*@unused@*/ x -#else -# define UNUSED(x) x -#endif - namespace OpenBabel { @@ -283,7 +274,7 @@ class OBConversion; //used only as pointer //! \brief Base type does nothing //! Made virtual around r3535 to simplify code which passes around OBBase*. //Currently no title data member in base class. - virtual const char *GetTitle(bool UNUSED(replaceNewlines) = true) const { return "";} + virtual const char *GetTitle(OB_UNUSED bool replaceNewlines = true) const { return "";} virtual void SetTitle(const char *) {} //! \name Generic data handling methods (via OBGenericData) diff --git a/include/openbabel/forcefield.h b/include/openbabel/forcefield.h index 55ae36ee53..997a44ce01 100644 --- a/include/openbabel/forcefield.h +++ b/include/openbabel/forcefield.h @@ -910,56 +910,56 @@ const double GAS_CONSTANT = 8.31446261815324e-3 / KCAL_TO_KJ; //!< kcal mol^-1 * OBFF_LOGLVL_MEDIUM: energy for individual energy terms \n * OBFF_LOGLVL_HIGH: energy for individual energy interactions \n */ - virtual double Energy(bool UNUSED(gradients) = true) { return 0.0f; } + virtual double Energy(OB_UNUSED bool gradients = true) { return 0.0f; } /*! \param gradients Set to true when the gradients need to be calculated * (needs to be done before calling GetGradient()). * \return Bond stretching energy. * \par Output to log: * see Energy() */ - virtual double E_Bond(bool UNUSED(gradients) = true) { return 0.0f; } + virtual double E_Bond(OB_UNUSED bool gradients = true) { return 0.0f; } /*! \param gradients Set to true when the gradients need to be calculated * (needs to be done before calling GetGradient()). * \return Angle bending energy. * \par Output to log: * see Energy() */ - virtual double E_Angle(bool UNUSED(gradients) = true) { return 0.0f; } + virtual double E_Angle(OB_UNUSED bool gradients = true) { return 0.0f; } /*! \param gradients Set to true when the gradients need to be calculated * (needs to be done before calling GetGradient()). * \return Stretch bending energy. * \par Output to log: * see Energy() */ - virtual double E_StrBnd(bool UNUSED(gradients) = true) { return 0.0f; } + virtual double E_StrBnd(OB_UNUSED bool gradients = true) { return 0.0f; } /*! \param gradients Set to true when the gradients need to be calculated * (needs to be done before calling GetGradient()). * \return Torsional energy. * \par Output to log: * see Energy() */ - virtual double E_Torsion(bool UNUSED(gradients) = true) { return 0.0f; } + virtual double E_Torsion(OB_UNUSED bool gradients = true) { return 0.0f; } /*! \param gradients Set to true when the gradients need to be calculated * (needs to be done before calling GetGradient()). * \return Out-Of-Plane bending energy. * \par Output to log: * see Energy() */ - virtual double E_OOP(bool UNUSED(gradients) = true) { return 0.0f; } + virtual double E_OOP(OB_UNUSED bool gradients = true) { return 0.0f; } /*! \param gradients Set to true when the gradients need to be calculated * (needs to be done before calling GetGradient()). * \return Van der Waals energy. * \par Output to log: * see Energy() */ - virtual double E_VDW(bool UNUSED(gradients) = true) { return 0.0f; } + virtual double E_VDW(OB_UNUSED bool gradients = true) { return 0.0f; } /*! \param gradients Set to true when the gradients need to be calculated * (needs to be done before calling GetGradient()). * \return Electrostatic energy. * \par Output to log: * see Energy() */ - virtual double E_Electrostatic(bool UNUSED(gradients) = true) { return 0.0f; } + virtual double E_Electrostatic(OB_UNUSED bool gradients = true) { return 0.0f; } //@} ///////////////////////////////////////////////////////////////////////// diff --git a/include/openbabel/rotor.h b/include/openbabel/rotor.h index 9f3e622bc7..564789f76f 100644 --- a/include/openbabel/rotor.h +++ b/include/openbabel/rotor.h @@ -24,15 +24,6 @@ GNU General Public License for more details. #include #include -#ifdef UNUSED -#elif (__GNUC__ == 4) -# define UNUSED(x) UNUSED_ ## x __attribute__((unused)) -#elif defined(__LCLINT__) -# define UNUSED(x) /*@unused@*/ x -#else -# define UNUSED(x) x -#endif - namespace OpenBabel { class OBRing; @@ -425,7 +416,7 @@ namespace OpenBabel ///@name Deprecated ///@{ /** @deprecated Has no effect. */ - void SetDelta(double UNUSED(d)) {} + void SetDelta(OB_UNUSED double d) {} /** @deprecated Has no effect. */ double GetDelta() { return 10.0; } /** @deprecated */ @@ -441,7 +432,7 @@ namespace OpenBabel /** @deprecated Bad name, see GetTorsionValues() */ std::vector &GetResolution() { return _torsionAngles; } /** @deprecated */ - void SetNumCoords(int UNUSED(nc)) {} + void SetNumCoords(OB_UNUSED int nc) {} ///@} }; diff --git a/src/config.h.cmake b/src/config.h.cmake index 78b2ccc864..4b97b523c1 100644 --- a/src/config.h.cmake +++ b/src/config.h.cmake @@ -31,6 +31,13 @@ #define OB_HIDDEN #endif +// maybe_unused attribute (C++17) +#if __cplusplus >= 201402L && defined(__has_cpp_attribute) && __has_cpp_attribute(maybe_unused) >= 201603L && !defined(SWIG) + #define OB_UNUSED [[maybe_unused]] +#else + #define OB_UNUSED +#endif + /* Used to export symbols for DLL / shared library builds */ #if defined(MAKE_OBDLL) // e.g. in src/main.cpp #ifndef EXTERN