Skip to content

Commit

Permalink
[mojo-sdk] Remove mojo::ignore_result and MOJO_MOVE_ONLY_TYPE
Browse files Browse the repository at this point in the history
BUG=534695

Review URL: https://codereview.chromium.org/1759393002

Cr-Commit-Position: refs/heads/master@{#379394}
  • Loading branch information
akmistry authored and Commit bot committed Mar 4, 2016
1 parent d6d8ce1 commit 993c17f
Show file tree
Hide file tree
Showing 12 changed files with 13 additions and 96 deletions.
2 changes: 1 addition & 1 deletion mojo/public/cpp/bindings/array.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace mojo {
// meaning that no value has been assigned to it. Null is distinct from empty.
template <typename T>
class Array {
MOJO_MOVE_ONLY_TYPE(Array)
MOVE_ONLY_TYPE_FOR_CPP_03(Array);
public:
using ConstRefType = typename std::vector<T>::const_reference;
using RefType = typename std::vector<T>::reference;
Expand Down
2 changes: 1 addition & 1 deletion mojo/public/cpp/bindings/interface_ptr.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class AssociatedGroup;
// any thread.
template <typename Interface>
class InterfacePtr {
DISALLOW_COPY_AND_ASSIGN_WITH_MOVE_FOR_BIND(InterfacePtr)
DISALLOW_COPY_AND_ASSIGN_WITH_MOVE_FOR_BIND(InterfacePtr);

public:
using GenericInterface = typename Interface::GenericInterface;
Expand Down
2 changes: 1 addition & 1 deletion mojo/public/cpp/bindings/interface_ptr_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace mojo {
// interface implementation, which could be used to construct an InterfacePtr.
template <typename Interface>
class InterfacePtrInfo {
MOJO_MOVE_ONLY_TYPE(InterfacePtrInfo);
MOVE_ONLY_TYPE_FOR_CPP_03(InterfacePtrInfo);

public:
InterfacePtrInfo() : version_(0u) {}
Expand Down
2 changes: 1 addition & 1 deletion mojo/public/cpp/bindings/interface_request.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace mojo {
// if the client did not provide a message pipe.
template <typename Interface>
class InterfaceRequest {
MOJO_MOVE_ONLY_TYPE(InterfaceRequest)
MOVE_ONLY_TYPE_FOR_CPP_03(InterfaceRequest);
public:
// Constructs an empty InterfaceRequest, representing that the client is not
// requesting an implementation of Interface.
Expand Down
2 changes: 1 addition & 1 deletion mojo/public/cpp/bindings/lib/filter_chain.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace mojo {
namespace internal {

class FilterChain {
MOJO_MOVE_ONLY_TYPE(FilterChain)
MOVE_ONLY_TYPE_FOR_CPP_03(FilterChain)

public:
// Doesn't take ownership of |sink|. Therefore |sink| has to stay alive while
Expand Down
2 changes: 1 addition & 1 deletion mojo/public/cpp/bindings/map.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace mojo {
// using the insert() method.
template <typename Key, typename Value>
class Map {
MOJO_MOVE_ONLY_TYPE(Map)
MOVE_ONLY_TYPE_FOR_CPP_03(Map);

public:
// Map keys cannot be move only classes.
Expand Down
2 changes: 1 addition & 1 deletion mojo/public/cpp/bindings/strong_binding.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ namespace mojo {
// bound, it may be bound or destroyed on any thread.
template <typename Interface>
class StrongBinding {
MOJO_MOVE_ONLY_TYPE(StrongBinding)
MOVE_ONLY_TYPE_FOR_CPP_03(StrongBinding);

public:
explicit StrongBinding(Interface* impl) : binding_(impl) {}
Expand Down
4 changes: 2 additions & 2 deletions mojo/public/cpp/bindings/struct_ptr.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class StructHelper {
// Smart pointer wrapping a mojom structure with move-only semantics.
template <typename Struct>
class StructPtr {
MOJO_MOVE_ONLY_TYPE(StructPtr)
MOVE_ONLY_TYPE_FOR_CPP_03(StructPtr);

public:

Expand Down Expand Up @@ -117,7 +117,7 @@ class StructPtr {
// Designed to be used when Struct is small and copyable.
template <typename Struct>
class InlinedStructPtr {
MOJO_MOVE_ONLY_TYPE(InlinedStructPtr);
MOVE_ONLY_TYPE_FOR_CPP_03(InlinedStructPtr);

public:

Expand Down
3 changes: 2 additions & 1 deletion mojo/public/cpp/bindings/tests/container_test_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <stddef.h>

#include "base/move.h"
#include "mojo/public/cpp/system/macros.h"

namespace mojo {
Expand All @@ -30,7 +31,7 @@ class CopyableType {
};

class MoveOnlyType {
MOJO_MOVE_ONLY_TYPE(MoveOnlyType)
MOVE_ONLY_TYPE_FOR_CPP_03(MoveOnlyType);
public:
typedef MoveOnlyType Data_;
MoveOnlyType();
Expand Down
3 changes: 2 additions & 1 deletion mojo/public/cpp/system/handle.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include "base/compiler_specific.h"
#include "base/macros.h"
#include "base/move.h"
#include "mojo/public/c/system/functions.h"
#include "mojo/public/c/system/types.h"
#include "mojo/public/cpp/system/macros.h"
Expand Down Expand Up @@ -72,7 +73,7 @@ namespace mojo {
// like the C++11 |unique_ptr|.
template <class HandleType>
class ScopedHandleBase {
MOJO_MOVE_ONLY_TYPE(ScopedHandleBase)
MOVE_ONLY_TYPE_FOR_CPP_03(ScopedHandleBase);

public:
ScopedHandleBase() {}
Expand Down
25 changes: 0 additions & 25 deletions mojo/public/cpp/system/macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,6 @@

#include "mojo/public/c/system/macros.h" // Symbols exposed.

// Used to make a type non-copyable. See Chromium's base/move.h for more
// details. The MoveOnlyTypeForCPP03 typedef is for Chromium's base/callback.h
// to tell that this type is move-only, allowing these types to be bound or
// passed to Callbacks.
#define MOJO_MOVE_ONLY_TYPE(type) \
private: \
type(const type&) = delete; \
void operator=(const type&) = delete; \
\
public: \
typedef void MoveOnlyTypeForCPP03; \
\
private:

// The C++ standard requires that static const members have an out-of-class
// definition (in a single compilation unit), but MSVC chokes on this (when
// language extensions, which are required, are enabled). (You're only likely to
Expand All @@ -50,15 +36,4 @@
#define MOJO_STATIC_CONST_MEMBER_DEFINITION
#endif

namespace mojo {

// Used to explicitly mark the return value of a function as unused. (You this
// if you are really sure you don't want to do anything with the return value of
// a function marked with |WARN_UNUSED_RESULT|.
template <typename T>
inline void ignore_result(const T&) {
}

} // namespace mojo

#endif // MOJO_PUBLIC_CPP_SYSTEM_MACROS_H_
60 changes: 0 additions & 60 deletions mojo/public/cpp/system/tests/macros_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,71 +56,11 @@ TEST(MacrosCppTest, Override) {
x.AlsoToBeOverridden();
}

// Note: MSVS is very strict (and arguably buggy) about warnings for classes
// defined in a local scope, so define these globally.
class MoveOnlyInt {
MOJO_MOVE_ONLY_TYPE(MoveOnlyInt)

public:
MoveOnlyInt() : is_set_(false), value_() {}
explicit MoveOnlyInt(int value) : is_set_(true), value_(value) {}
~MoveOnlyInt() {}

// Move-only constructor and operator=.
MoveOnlyInt(MoveOnlyInt&& other) { *this = std::move(other); }
MoveOnlyInt& operator=(MoveOnlyInt&& other) {
if (&other != this) {
is_set_ = other.is_set_;
value_ = other.value_;
other.is_set_ = false;
}
return *this;
}

int value() const {
assert(is_set());
return value_;
}
bool is_set() const { return is_set_; }

private:
bool is_set_;
int value_;
};

TEST(MacrosCppTest, MoveOnlyType) {
MoveOnlyInt x(123);
EXPECT_TRUE(x.is_set());
EXPECT_EQ(123, x.value());
MoveOnlyInt y;
EXPECT_FALSE(y.is_set());
y = std::move(x);
EXPECT_FALSE(x.is_set());
EXPECT_TRUE(y.is_set());
EXPECT_EQ(123, y.value());
MoveOnlyInt z(std::move(y));
EXPECT_FALSE(y.is_set());
EXPECT_TRUE(z.is_set());
EXPECT_EQ(123, z.value());
}

// Use it, to make sure things get linked in and to avoid any warnings about
// unused things.
TEST(MacrosCppTest, StaticConstMemberDefinition) {
EXPECT_EQ(123, StructWithStaticConstMember::kStaticConstMember);
}

// The test for |ignore_result()| is also just a compilation test. (Note that
// |WARN_UNUSED_RESULT| can only be used in the prototype.
int ReturnsIntYouMustUse() WARN_UNUSED_RESULT;

int ReturnsIntYouMustUse() {
return 123;
}

TEST(MacrosCppTest, IgnoreResult) {
ignore_result(ReturnsIntYouMustUse());
}

} // namespace
} // namespace mojo

0 comments on commit 993c17f

Please sign in to comment.