Skip to content

Commit

Permalink
Merge pull request #550 from dartsim/function_warning_suppress
Browse files Browse the repository at this point in the history
Suppress warnings in Function.cpp
  • Loading branch information
jslee02 committed Nov 5, 2015
2 parents ebc0ad8 + c629edd commit 8d003b1
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 2 deletions.
44 changes: 44 additions & 0 deletions dart/common/Deprecated.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
* POSSIBILITY OF SUCH DAMAGE.
*/

#include "dart/config.h"

#ifndef DART_COMMON_DEPRECATED_H_
#define DART_COMMON_DEPRECATED_H_

Expand All @@ -54,4 +56,46 @@
#define FORCEINLINE
#endif

// We define two convenient macros that can be used to suppress
// deprecated-warnings for a specific code block rather than a whole project.
// This macros would be useful when you need to call deprecated function for
// some reason (e.g., for backward compatibility) but don't want warnings.
//
// Example code:
//
// deprecated_function() // warning
//
// DART_SUPPRESS_DEPRECATED_BEGIN
// deprecated_function() // okay, no warning
// DART_SUPPRESS_DEPRECATED_END
//
#if defined (DART_COMPILER_GCC)

#define DART_SUPPRESS_DEPRECATED_BEGIN \
_Pragma("GCC diagnostic push") \
_Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")

#define DART_SUPPRESS_DEPRECATED_END \
_Pragma("GCC diagnostic pop")

#elif defined (DART_COMPILER_CLANG)

#define DART_SUPPRESS_DEPRECATED_BEGIN \
_Pragma("clang diagnostic push") \
_Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"")

#define DART_SUPPRESS_DEPRECATED_END \
_Pragma("clang diagnostic pop")

#elif defined (DART_COMPILER_MSVC)

#define DART_SUPPRESS_DEPRECATED_BEGIN \
__pragma(warning(push)) \
__pragma(warning(disable:4996))

#define DART_SUPPRESS_DEPRECATED_END \
__pragma(warning(pop))

#endif

#endif // DART_COMMON_DEPRECATED_H_
9 changes: 9 additions & 0 deletions dart/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@
(DART_MAJOR_VERSION < x || (DART_MAJOR_VERSION <= x && \
(DART_MINOR_VERSION < y || (DART_MINOR_VERSION <= y))))

// Detect the compiler
#if defined(__clang__)
#define DART_COMPILER_CLANG
#elif defined(__GNUC__) || defined(__GNUG__)
#define DART_COMPILER_GCC
#elif defined(_MSC_VER)
#define DART_COMPILER_MSVC
#endif

#cmakedefine BUILD_TYPE_DEBUG 1
#cmakedefine BUILD_TYPE_RELEASE 1
#cmakedefine BUILD_TYPE_RELWITHDEBINFO 1
Expand Down
12 changes: 10 additions & 2 deletions dart/optimizer/Function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,13 @@ double Function::eval(Eigen::Map<const Eigen::VectorXd>& _x)
double Function::eval(const Eigen::VectorXd& _x)
{
// TODO(MXG): This is for backwards compatibility. This function should be
// made pure abstract with the next major version-up
// made pure abstract with the next major version-up. We suppress the
// deprecated-warnings until then (see #544).
Eigen::Map<const Eigen::VectorXd> temp(_x.data(), _x.size());

DART_SUPPRESS_DEPRECATED_BEGIN
return eval(temp);
DART_SUPPRESS_DEPRECATED_END
}

//==============================================================================
Expand All @@ -101,9 +105,13 @@ void Function::evalGradient(Eigen::Map<const Eigen::VectorXd>& _x,
void Function::evalGradient(const Eigen::VectorXd& _x,
Eigen::Map<Eigen::VectorXd> _grad)
{
// TODO(MXG): This is for backwards compatibility
// TODO(MXG): This is for backwards compatibility. We suppress the
// deprecated-warnings until then (see #544).
Eigen::Map<const Eigen::VectorXd> temp(_x.data(), _x.size());

DART_SUPPRESS_DEPRECATED_BEGIN
evalGradient(temp, _grad);
DART_SUPPRESS_DEPRECATED_END
}

//==============================================================================
Expand Down

0 comments on commit 8d003b1

Please sign in to comment.