From 1b3eb6ef34620c1203263d76ec169ef0853789cc Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Mon, 20 Apr 2020 19:03:58 -0400 Subject: Googletest export Explicitly define copy constructors used in googletest tests As of C++11, providing a user-declared copy assignment operator should suppress the availability of an implicit default copy constructor. Classes that provide (or delete) a copy assignment operator must provide their own copy constructor if one is desired. This may be an explicit default copy constructor if appropriate. As googletest is a C++11 codebase, this change should be made without qualification. This addresses the -Wdeprecated-copy warnings issued by trunk clang: While compiling googletest/test/googletest-death-test-test.cc: In file included from .../googletest/test/googletest-death-test-test.cc:33: .../googletest/include/gtest/gtest-death-test.h:196:8: error: definition of implicit copy constructor for 'ExitedWithCode' is deprecated because it has a user-declared copy assignment operator [-Werror,-Wdeprecated-copy] void operator=(const ExitedWithCode& other); ^ .../googletest/test/googletest-death-test-test.cc:279:16: note: in implicit copy constructor for 'testing::ExitedWithCode' first required here EXPECT_PRED1(pred0, status0); ^ While compiling googletest/test/googletest-param-test-test.cc: .../googletest/test/googletest-param-test-test.cc:502:8: error: definition of implicit copy constructor for 'NonDefaultConstructAssignString' is deprecated because it has a user-declared copy assignment operator [-Werror,-Wdeprecated-copy] void operator=(const NonDefaultConstructAssignString&); ^ .../googletest/test/googletest-param-test-test.cc:507:36: note: in implicit copy constructor for 'NonDefaultConstructAssignString' first required here Combine(Values(0, 1), Values(NonDefaultConstructAssignString("A"), This matches other changes made elsewhere in the googletest codebase, such as 306f3754a71d. Perhaps those previous changes did not consider test code. PiperOrigin-RevId: 307495126 --- googletest/include/gtest/gtest-death-test.h | 5 ++--- googletest/test/googletest-param-test-test.cc | 10 +++++----- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/googletest/include/gtest/gtest-death-test.h b/googletest/include/gtest/gtest-death-test.h index dc878ffb..2bd41cf3 100644 --- a/googletest/include/gtest/gtest-death-test.h +++ b/googletest/include/gtest/gtest-death-test.h @@ -190,11 +190,10 @@ GTEST_API_ bool InDeathTestChild(); class GTEST_API_ ExitedWithCode { public: explicit ExitedWithCode(int exit_code); + ExitedWithCode(const ExitedWithCode&) = default; + void operator=(const ExitedWithCode& other) = delete; bool operator()(int exit_status) const; private: - // No implementation - assignment is unsupported. - void operator=(const ExitedWithCode& other); - const int exit_code_; }; diff --git a/googletest/test/googletest-param-test-test.cc b/googletest/test/googletest-param-test-test.cc index 6ba89654..0ab0d6f3 100644 --- a/googletest/test/googletest-param-test-test.cc +++ b/googletest/test/googletest-param-test-test.cc @@ -490,16 +490,16 @@ TEST(CombineTest, CombineWithMaxNumberOfParameters) { class NonDefaultConstructAssignString { public: NonDefaultConstructAssignString(const std::string& s) : str_(s) {} + NonDefaultConstructAssignString(const NonDefaultConstructAssignString&) = + default; + + NonDefaultConstructAssignString() = delete; + void operator=(const NonDefaultConstructAssignString&) = delete; const std::string& str() const { return str_; } private: std::string str_; - - // Not default constructible - NonDefaultConstructAssignString(); - // Not assignable - void operator=(const NonDefaultConstructAssignString&); }; TEST(CombineTest, NonDefaultConstructAssign) { -- cgit v1.2.3