forked from RobotLocomotion/drake
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[common] DRAKE_DEFAULT_COPY_AND_MOVE_AND_ASSIGN detects mis-uses (Rob…
…otLocomotion#15884) Add unit test advice to complement the new built-in checking. This commit also contains a demonstration of related changes: * Add (positive) unit test for this macro. * Fix name_value to correctly document its (pre-existing) non-copyable behavior. * Remove useless unit test for a defaulted copy constructor.
- Loading branch information
1 parent
1870392
commit b3dc213
Showing
6 changed files
with
81 additions
and
20 deletions.
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
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,41 @@ | ||
#include "drake/common/drake_copyable.h" | ||
|
||
#include <gtest/gtest.h> | ||
|
||
namespace drake { | ||
namespace { | ||
|
||
// When a class has a user-defined destructor, the implicit generation of the | ||
// copy constructor and copy-assignment operator is deprecated as of C++11. | ||
// | ||
// Under Drake's Clang configuration, relying on the deprecated operator | ||
// produces an error under -Werror=deprecated. | ||
// | ||
// Therefore, if DRAKE_DEFAULT_COPY_AND_MOVE_AND_ASSIGN failed to default those | ||
// operations, then this unit test would no longer compile (under Clang). | ||
class Example { | ||
public: | ||
DRAKE_DEFAULT_COPY_AND_MOVE_AND_ASSIGN(Example); | ||
Example() = default; | ||
~Example() {} | ||
}; | ||
|
||
GTEST_TEST(DrakeCopyableTest, CopyConstruct) { | ||
Example foo; | ||
Example bar(foo); | ||
} | ||
|
||
GTEST_TEST(DrakeCopyableTest, CopyAssign) { | ||
Example foo, bar; | ||
bar = foo; | ||
} | ||
|
||
// Confirm that private (and by association, protected) access for this macro | ||
// is permitted. If not, this class would fail to compile. | ||
class ExamplePrivate { | ||
private: | ||
DRAKE_DEFAULT_COPY_AND_MOVE_AND_ASSIGN(ExamplePrivate); | ||
}; | ||
|
||
} // namespace | ||
} // namespace drake |
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