Skip to content

Commit

Permalink
Use [[maybe_unused]] attribute (C++17) and specify -Wunused-variable
Browse files Browse the repository at this point in the history
  • Loading branch information
e-kwsm committed Nov 6, 2019
1 parent f84536d commit 9e26c73
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 29 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Expand Up @@ -15,6 +15,8 @@ endif()

include (CheckCXXCompilerFlag)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wunused-variable")

CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
if(COMPILER_SUPPORTS_CXX11)
Expand Down
11 changes: 1 addition & 10 deletions include/openbabel/base.h
Expand Up @@ -28,15 +28,6 @@ GNU General Public License for more details.
#include <iostream>
#include <openbabel/tokenst.h>

#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
{

Expand Down Expand Up @@ -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)
Expand Down
16 changes: 8 additions & 8 deletions include/openbabel/forcefield.h
Expand Up @@ -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; }
//@}

/////////////////////////////////////////////////////////////////////////
Expand Down
13 changes: 2 additions & 11 deletions include/openbabel/rotor.h
Expand Up @@ -24,15 +24,6 @@ GNU General Public License for more details.
#include <openbabel/typer.h>
#include <openbabel/bitvec.h>

#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;
Expand Down Expand Up @@ -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 */
Expand All @@ -441,7 +432,7 @@ namespace OpenBabel
/** @deprecated Bad name, see GetTorsionValues() */
std::vector<double> &GetResolution() { return _torsionAngles; }
/** @deprecated */
void SetNumCoords(int UNUSED(nc)) {}
void SetNumCoords(OB_UNUSED int nc) {}
///@}

};
Expand Down
7 changes: 7 additions & 0 deletions src/config.h.cmake
Expand Up @@ -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
Expand Down

0 comments on commit 9e26c73

Please sign in to comment.