diff options
author | Abseil Team <absl-team@google.com> | 2018-10-04 22:28:05 (GMT) |
---|---|---|
committer | Gennadiy Civil <misterg@google.com> | 2018-10-05 16:54:14 (GMT) |
commit | 4bb49ed640e34e23187ad7ea689693ef9927033f (patch) | |
tree | 31bfca77d3e46134fddebe28118bcba3af711e45 /googlemock/include | |
parent | f13bbe2992d188e834339abe6f715b2b2f840a77 (diff) | |
download | googletest-4bb49ed640e34e23187ad7ea689693ef9927033f.zip googletest-4bb49ed640e34e23187ad7ea689693ef9927033f.tar.gz googletest-4bb49ed640e34e23187ad7ea689693ef9927033f.tar.bz2 |
Apply clang-tidy modernize-use-nullptr to googletest.
Now that googletest has moved to C++11, it should no longer
use NULL or 0 for the null pointer. This patch converts all
such usages to nullptr using clang-tidy.
This prevents LLVM from issuing -Wzero-as-null-pointer-constant
warnings.
PiperOrigin-RevId: 215814400
Diffstat (limited to 'googlemock/include')
-rw-r--r-- | googlemock/include/gmock/gmock-actions.h | 29 | ||||
-rw-r--r-- | googlemock/include/gmock/gmock-matchers.h | 48 | ||||
-rw-r--r-- | googlemock/include/gmock/gmock-spec-builders.h | 20 |
3 files changed, 47 insertions, 50 deletions
diff --git a/googlemock/include/gmock/gmock-actions.h b/googlemock/include/gmock/gmock-actions.h index b82313d..e3b3f09 100644 --- a/googlemock/include/gmock/gmock-actions.h +++ b/googlemock/include/gmock/gmock-actions.h @@ -137,7 +137,7 @@ template <typename T> class BuiltInDefaultValue<T*> { public: static bool Exists() { return true; } - static T* Get() { return NULL; } + static T* Get() { return nullptr; } }; // The following specializations define the default values for @@ -220,11 +220,11 @@ class DefaultValue { // Unsets the default value for type T. static void Clear() { delete producer_; - producer_ = NULL; + producer_ = nullptr; } // Returns true iff the user has set the default value for type T. - static bool IsSet() { return producer_ != NULL; } + static bool IsSet() { return producer_ != nullptr; } // Returns true if T has a default return value set by the user or there // exists a built-in default value. @@ -236,8 +236,8 @@ class DefaultValue { // otherwise returns the built-in default value. Requires that Exists() // is true, which ensures that the return value is well-defined. static T Get() { - return producer_ == NULL ? - internal::BuiltInDefaultValue<T>::Get() : producer_->Produce(); + return producer_ == nullptr ? internal::BuiltInDefaultValue<T>::Get() + : producer_->Produce(); } private: @@ -282,12 +282,10 @@ class DefaultValue<T&> { } // Unsets the default value for type T&. - static void Clear() { - address_ = NULL; - } + static void Clear() { address_ = nullptr; } // Returns true iff the user has set the default value for type T&. - static bool IsSet() { return address_ != NULL; } + static bool IsSet() { return address_ != nullptr; } // Returns true if T has a default return value set by the user or there // exists a built-in default value. @@ -299,8 +297,8 @@ class DefaultValue<T&> { // otherwise returns the built-in default value if there is one; // otherwise aborts the process. static T& Get() { - return address_ == NULL ? - internal::BuiltInDefaultValue<T&>::Get() : *address_; + return address_ == nullptr ? internal::BuiltInDefaultValue<T&>::Get() + : *address_; } private: @@ -318,11 +316,11 @@ class DefaultValue<void> { // Points to the user-set default value for type T. template <typename T> -typename DefaultValue<T>::ValueProducer* DefaultValue<T>::producer_ = NULL; +typename DefaultValue<T>::ValueProducer* DefaultValue<T>::producer_ = nullptr; // Points to the user-set default value for type T&. template <typename T> -T* DefaultValue<T&>::address_ = NULL; +T* DefaultValue<T&>::address_ = nullptr; // Implement this interface to define an action for function type F. template <typename F> @@ -1108,8 +1106,9 @@ Action<To>::Action(const Action<From>& from) #if GTEST_LANG_CXX11 fun_(from.fun_), #endif - impl_(from.impl_ == NULL ? NULL - : new internal::ActionAdaptor<To, From>(from)) { + impl_(from.impl_ == nullptr + ? nullptr + : new internal::ActionAdaptor<To, From>(from)) { } // Creates an action that returns 'value'. 'value' is passed by value diff --git a/googlemock/include/gmock/gmock-matchers.h b/googlemock/include/gmock/gmock-matchers.h index b4961d4..0f7745e 100644 --- a/googlemock/include/gmock/gmock-matchers.h +++ b/googlemock/include/gmock/gmock-matchers.h @@ -94,8 +94,7 @@ class MatchResultListener { // is NULL. template <typename T> MatchResultListener& operator<<(const T& x) { - if (stream_ != NULL) - *stream_ << x; + if (stream_ != nullptr) *stream_ << x; return *this; } @@ -106,7 +105,7 @@ class MatchResultListener { // the match result. A matcher's MatchAndExplain() method can use // this information to avoid generating the explanation when no one // intends to hear it. - bool IsInterested() const { return stream_ != NULL; } + bool IsInterested() const { return stream_ != nullptr; } private: ::std::ostream* const stream_; @@ -261,7 +260,7 @@ struct AnyGe { // A match result listener that ignores the explanation. class DummyMatchResultListener : public MatchResultListener { public: - DummyMatchResultListener() : MatchResultListener(NULL) {} + DummyMatchResultListener() : MatchResultListener(nullptr) {} private: GTEST_DISALLOW_COPY_AND_ASSIGN_(DummyMatchResultListener); @@ -333,7 +332,7 @@ class MatcherBase { const MatcherInterface<U>* impl, typename internal::EnableIf< !internal::IsSame<U, GTEST_REFERENCE_TO_CONST_(U)>::value>::type* = - NULL) + nullptr) : impl_(new internal::MatcherInterfaceAdapter<U>(impl)) {} virtual ~MatcherBase() {} @@ -375,9 +374,11 @@ class Matcher : public internal::MatcherBase<T> { : internal::MatcherBase<T>(impl) {} template <typename U> - explicit Matcher(const MatcherInterface<U>* impl, - typename internal::EnableIf<!internal::IsSame< - U, GTEST_REFERENCE_TO_CONST_(U)>::value>::type* = NULL) + explicit Matcher( + const MatcherInterface<U>* impl, + typename internal::EnableIf< + !internal::IsSame<U, GTEST_REFERENCE_TO_CONST_(U)>::value>::type* = + nullptr) : internal::MatcherBase<T>(impl) {} // Implicit constructor here allows people to write @@ -850,7 +851,7 @@ namespace internal { // If the explanation is not empty, prints it to the ostream. inline void PrintIfNotEmpty(const std::string& explanation, ::std::ostream* os) { - if (explanation != "" && os != NULL) { + if (explanation != "" && os != nullptr) { *os << ", " << explanation; } } @@ -1321,7 +1322,7 @@ class StrEqualityMatcher { // wchar_t* template <typename CharType> bool MatchAndExplain(CharType* s, MatchResultListener* listener) const { - if (s == NULL) { + if (s == nullptr) { return !expect_eq_; } return MatchAndExplain(StringType(s), listener); @@ -1391,7 +1392,7 @@ class HasSubstrMatcher { // wchar_t* template <typename CharType> bool MatchAndExplain(CharType* s, MatchResultListener* listener) const { - return s != NULL && MatchAndExplain(StringType(s), listener); + return s != nullptr && MatchAndExplain(StringType(s), listener); } // Matches anything that can convert to StringType. @@ -1448,7 +1449,7 @@ class StartsWithMatcher { // wchar_t* template <typename CharType> bool MatchAndExplain(CharType* s, MatchResultListener* listener) const { - return s != NULL && MatchAndExplain(StringType(s), listener); + return s != nullptr && MatchAndExplain(StringType(s), listener); } // Matches anything that can convert to StringType. @@ -1504,7 +1505,7 @@ class EndsWithMatcher { // wchar_t* template <typename CharType> bool MatchAndExplain(CharType* s, MatchResultListener* listener) const { - return s != NULL && MatchAndExplain(StringType(s), listener); + return s != nullptr && MatchAndExplain(StringType(s), listener); } // Matches anything that can convert to StringType. @@ -1557,7 +1558,7 @@ class MatchesRegexMatcher { // wchar_t* template <typename CharType> bool MatchAndExplain(CharType* s, MatchResultListener* listener) const { - return s != NULL && MatchAndExplain(std::string(s), listener); + return s != nullptr && MatchAndExplain(std::string(s), listener); } // Matches anything that can convert to std::string. @@ -2347,8 +2348,7 @@ class PointeeMatcher { virtual bool MatchAndExplain(Pointer pointer, MatchResultListener* listener) const { - if (GetRawPointer(pointer) == NULL) - return false; + if (GetRawPointer(pointer) == nullptr) return false; *listener << "which points to "; return MatchPrintAndExplain(*pointer, matcher_, listener); @@ -2431,7 +2431,7 @@ class WhenDynamicCastToMatcher<To&> : public WhenDynamicCastToMatcherBase<To&> { bool MatchAndExplain(From& from, MatchResultListener* listener) const { // We don't want an std::bad_cast here, so do the cast with pointers. To* to = dynamic_cast<To*>(&from); - if (to == NULL) { + if (to == nullptr) { *listener << "which cannot be dynamic_cast to " << this->GetToName(); return false; } @@ -2485,8 +2485,7 @@ class FieldMatcher { bool MatchAndExplainImpl(true_type /* is_pointer */, const Class* p, MatchResultListener* listener) const { - if (p == NULL) - return false; + if (p == nullptr) return false; *listener << "which points to an object "; // Since *p has a field, it must be a class/struct/union type and @@ -2570,8 +2569,7 @@ class PropertyMatcher { bool MatchAndExplainImpl(true_type /* is_pointer */, const Class* p, MatchResultListener* listener) const { - if (p == NULL) - return false; + if (p == nullptr) return false; *listener << "which points to an object "; // Since *p has a property method, it must be a class/struct/union @@ -2615,7 +2613,7 @@ struct CallableTraits<ResType(*)(ArgType)> { typedef ResType(*StorageType)(ArgType); static void CheckIsValid(ResType(*f)(ArgType)) { - GTEST_CHECK_(f != NULL) + GTEST_CHECK_(f != nullptr) << "NULL function pointer is passed into ResultOf()."; } template <typename T> @@ -2857,7 +2855,7 @@ class ContainerEqMatcher { return true; ::std::ostream* const os = listener->stream(); - if (os != NULL) { + if (os != nullptr) { // Something is different. Check for extra values first. bool printed_header = false; for (typename LhsStlContainer::const_iterator it = @@ -4136,11 +4134,11 @@ class AnyCastMatcher { ::testing::MatchResultListener* listener) const { if (!listener->IsInterested()) { const T* ptr = any_cast<T>(&value); - return ptr != NULL && matcher_.Matches(*ptr); + return ptr != nullptr && matcher_.Matches(*ptr); } const T* elem = any_cast<T>(&value); - if (elem == NULL) { + if (elem == nullptr) { *listener << "whose value is not of type '" << GetTypeName() << "'"; return false; } diff --git a/googlemock/include/gmock/gmock-spec-builders.h b/googlemock/include/gmock/gmock-spec-builders.h index 436e2d8..c8e864c 100644 --- a/googlemock/include/gmock/gmock-spec-builders.h +++ b/googlemock/include/gmock/gmock-spec-builders.h @@ -1213,7 +1213,7 @@ class TypedExpectation : public ExpectationBase { // FIXME: allow the user to control whether // unexpected calls should fail immediately or continue using a // flag --gmock_unexpected_calls_are_fatal. - return NULL; + return nullptr; } IncrementCallCount(); @@ -1498,7 +1498,7 @@ class FunctionMockerBase : public UntypedFunctionMockerBase { return spec; } - return NULL; + return nullptr; } // Performs the default action of this mock function on the given @@ -1513,7 +1513,7 @@ class FunctionMockerBase : public UntypedFunctionMockerBase { const std::string& call_description) const { const OnCallSpec<F>* const spec = this->FindOnCallSpec(args); - if (spec != NULL) { + if (spec != nullptr) { return spec->GetAction().Perform(internal::move(args)); } const std::string message = @@ -1630,7 +1630,7 @@ class FunctionMockerBase : public UntypedFunctionMockerBase { // Adds this expectation into the implicit sequence if there is one. Sequence* const implicit_sequence = g_gmock_implicit_sequence.get(); - if (implicit_sequence != NULL) { + if (implicit_sequence != nullptr) { implicit_sequence->AddExpectation(Expectation(untyped_expectation)); } @@ -1649,7 +1649,7 @@ class FunctionMockerBase : public UntypedFunctionMockerBase { ::std::ostream* os) const { const OnCallSpec<F>* const spec = FindOnCallSpec(args); - if (spec == NULL) { + if (spec == nullptr) { *os << (internal::type_equals<Result, void>::value ? "returning directly.\n" : "returning default value.\n"); @@ -1699,9 +1699,9 @@ class FunctionMockerBase : public UntypedFunctionMockerBase { *static_cast<const ArgumentTuple*>(untyped_args); MutexLock l(&g_gmock_mutex); TypedExpectation<F>* exp = this->FindMatchingExpectationLocked(args); - if (exp == NULL) { // A match wasn't found. + if (exp == nullptr) { // A match wasn't found. this->FormatUnexpectedCallMessageLocked(args, what, why); - return NULL; + return nullptr; } // This line must be done before calling GetActionForArguments(), @@ -1709,8 +1709,8 @@ class FunctionMockerBase : public UntypedFunctionMockerBase { // its saturation status. *is_excessive = exp->IsSaturated(); const Action<F>* action = exp->GetActionForArguments(this, args, what, why); - if (action != NULL && action->IsDoDefault()) - action = NULL; // Normalize "do default" to NULL. + if (action != nullptr && action->IsDoDefault()) + action = nullptr; // Normalize "do default" to NULL. *untyped_action = action; return exp; } @@ -1740,7 +1740,7 @@ class FunctionMockerBase : public UntypedFunctionMockerBase { return exp; } } - return NULL; + return nullptr; } // Returns a message that the arguments don't match any expectation. |