forked from RobotLocomotion/drake
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
111 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#pragma once | ||
|
||
/** @file | ||
Provides a portable macro for use in generating compile-time warnings for | ||
use of code that is permitted but discouraged. **/ | ||
|
||
#ifdef DRAKE_DOXYGEN_CXX | ||
/** Use `DRAKE_DEPRECATED("message")` to discourage use of particular | ||
classes, typedefs, variables, non-static data members, functions, arguments, | ||
enumerations, and template specializations. A compile time warning will be | ||
issued displaying the given message, preceded by "DRAKE DEPRECATED: ". | ||
This is typically used for constructs that have been replaced by something | ||
better and it is good practice to suggest the appropriate replacement in the | ||
deprecation message. Deprecation warnings are conventionally used to convey to | ||
users that a feature they are depending on will be removed in a future release. | ||
Usage: @code | ||
// Attribute comes *before* declaration of a deprecated function or variable; | ||
// no semicolon is allowed. | ||
DRAKE_DEPRECATED("f() is slow; use g() instead") | ||
int f(int arg); | ||
// Attribute comes *after* struct, class, enum keyword. | ||
class DRAKE_DEPRECATED("use MyNewClass instead") | ||
MyClass { | ||
}; | ||
@endcode | ||
This feature is standard in C++14 compilers via the `[[deprecated]]` attribute, | ||
and this macro will generate the standard attribute when compiled with a | ||
C++14-compliant compiler. **/ | ||
#define DRAKE_DEPRECATED(message) | ||
|
||
#else // DRAKE_DOXYGEN_CXX | ||
|
||
/* C++14 introduces a standard way to mark deprecated declarations. Before | ||
that we can use non-standard compiler hacks. */ | ||
#ifndef SWIG | ||
/* Make sure warnings are enabled in VC++; it is a common Windows hack for | ||
programmers to turn them off due to much inconvenient deprecation of useful | ||
things by Microsoft. */ | ||
#if _MSC_VER | ||
#pragma warning(default:4996) | ||
#endif | ||
/* Figure out the best form of deprecation for this compiler. */ | ||
#if __cplusplus >= 201402L | ||
/* C++14 */ | ||
#define DRAKE_DEPRECATED(MSG) [[deprecated("\nDRAKE DEPRECATED: " MSG)]] | ||
#elif _MSC_VER | ||
/* VC++ just says warning C4996 so add "DEPRECATED" to the message. */ | ||
#define DRAKE_DEPRECATED(MSG) \ | ||
__declspec(deprecated("\nDRAKE DEPRECATED: " MSG)) | ||
#else /* gcc or clang */ | ||
#define DRAKE_DEPRECATED(MSG) \ | ||
__attribute__((deprecated("\nDRAKE DEPRECATED: " MSG))) | ||
#endif | ||
#else /* Swigging */ | ||
#define DRAKE_DEPRECATED(MSG) | ||
#endif | ||
|
||
#endif // DRAKE_DOXYGEN_CXX |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#include "drake/common/drake_deprecated.h" | ||
|
||
#include <string> | ||
#include <vector> | ||
|
||
#include "gtest/gtest.h" | ||
|
||
/* This test only verifies that the Drake build can still succeed if a | ||
deprecated class or function is in use. I do not know how to test whether | ||
the desired warnings are actually issued except by inspection. */ | ||
|
||
namespace { | ||
|
||
class DRAKE_DEPRECATED("use MyNewClass instead") MyClass { | ||
}; | ||
|
||
class MyNewClass { | ||
}; | ||
|
||
DRAKE_DEPRECATED("don't use this function; use g() instead") | ||
int f(int arg) { return arg; } | ||
|
||
int g(int arg) { return arg; } | ||
|
||
GTEST_TEST(DrakeDeprecatedTest, ClassTest) { | ||
MyClass this_is_obsolete; | ||
MyNewClass this_is_not; | ||
(void)this_is_obsolete; // avoid "unused" warning | ||
(void)this_is_not; | ||
} | ||
|
||
GTEST_TEST(DrakeAssertDeathTest, FunctionTest) { | ||
int obsolete = f(1); | ||
int not_obsolete = g(1); | ||
(void)obsolete; | ||
(void)not_obsolete; | ||
} | ||
|
||
} // namespace |