From a1adec799a3252016dabce83f8effcebc51b8050 Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Thu, 12 Nov 2020 11:12:19 -0500 Subject: [PATCH] Googletest export Use a tagged constructor for FlatTuple instead. Some versions of MSVC are getting confused with that constructor and generating invalid code. PiperOrigin-RevId: 342050957 --- googlemock/include/gmock/gmock-generated-actions.h | 5 +++-- googletest/include/gtest/internal/gtest-internal.h | 11 +++-------- .../include/gtest/internal/gtest-param-util.h | 2 +- googletest/test/gtest_unittest.cc | 14 ++++++++++---- 4 files changed, 17 insertions(+), 15 deletions(-) diff --git a/googlemock/include/gmock/gmock-generated-actions.h b/googlemock/include/gmock/gmock-generated-actions.h index 9240ce9f..62909ea0 100644 --- a/googlemock/include/gmock/gmock-generated-actions.h +++ b/googlemock/include/gmock/gmock-generated-actions.h @@ -520,7 +520,8 @@ struct InvokeArgumentAction { auto operator()(Args&&... args) const -> decltype(internal::InvokeArgument( std::get(std::forward_as_tuple(std::forward(args)...)), std::declval()...)) { - internal::FlatTuple args_tuple(std::forward(args)...); + internal::FlatTuple args_tuple(FlatTupleConstructTag{}, + std::forward(args)...); return params.Apply([&](const Params&... unpacked_params) { auto&& callable = args_tuple.template Get(); return internal::InvokeArgument( @@ -564,7 +565,7 @@ template internal::InvokeArgumentAction::type...> InvokeArgument(Params&&... params) { return {internal::FlatTuple::type...>( - std::forward(params)...)}; + internal::FlatTupleConstructTag{}, std::forward(params)...)}; } #ifdef _MSC_VER diff --git a/googletest/include/gtest/internal/gtest-internal.h b/googletest/include/gtest/internal/gtest-internal.h index f00d78f2..8dc74bbb 100644 --- a/googletest/include/gtest/internal/gtest-internal.h +++ b/googletest/include/gtest/internal/gtest-internal.h @@ -1285,14 +1285,9 @@ class FlatTuple public: FlatTuple() = default; - template ::type...)>::value && - (sizeof...(T) >= 1)>::type> - explicit FlatTuple(Args&&... args) - : FlatTuple::FlatTupleBase(FlatTupleConstructTag{}, - std::forward(args)...) {} + template + explicit FlatTuple(FlatTupleConstructTag tag, Args&&... args) + : FlatTuple::FlatTupleBase(tag, std::forward(args)...) {} using FlatTuple::FlatTupleBase::Apply; using FlatTuple::FlatTupleBase::Get; diff --git a/googletest/include/gtest/internal/gtest-param-util.h b/googletest/include/gtest/internal/gtest-param-util.h index 05696a56..d12bd552 100644 --- a/googletest/include/gtest/internal/gtest-param-util.h +++ b/googletest/include/gtest/internal/gtest-param-util.h @@ -791,7 +791,7 @@ namespace internal { template class ValueArray { public: - explicit ValueArray(Ts... v) : v_(std::move(v)...) {} + explicit ValueArray(Ts... v) : v_(FlatTupleConstructTag{}, std::move(v)...) {} template operator ParamGenerator() const { // NOLINT diff --git a/googletest/test/gtest_unittest.cc b/googletest/test/gtest_unittest.cc index d08f9177..ac0f179a 100644 --- a/googletest/test/gtest_unittest.cc +++ b/googletest/test/gtest_unittest.cc @@ -7555,7 +7555,8 @@ TEST(FlatTuple, Basic) { EXPECT_EQ(0.0, tuple.Get<1>()); EXPECT_EQ(nullptr, tuple.Get<2>()); - tuple = FlatTuple(7, 3.2, "Foo"); + tuple = FlatTuple( + testing::internal::FlatTupleConstructTag{}, 7, 3.2, "Foo"); EXPECT_EQ(7, tuple.Get<0>()); EXPECT_EQ(3.2, tuple.Get<1>()); EXPECT_EQ(std::string("Foo"), tuple.Get<2>()); @@ -7573,7 +7574,8 @@ std::string AddIntToString(int i, const std::string& s) { TEST(FlatTuple, Apply) { using testing::internal::FlatTuple; - FlatTuple tuple{5, "Hello"}; + FlatTuple tuple{testing::internal::FlatTupleConstructTag{}, + 5, "Hello"}; // Lambda. EXPECT_TRUE(tuple.Apply([](int i, const std::string& s) -> bool { @@ -7647,7 +7649,8 @@ TEST(FlatTuple, ConstructorCalls) { ConstructionCounting::Reset(); { ConstructionCounting elem; - FlatTuple tuple{elem}; + FlatTuple tuple{ + testing::internal::FlatTupleConstructTag{}, elem}; } EXPECT_EQ(ConstructionCounting::default_ctor_calls, 1); EXPECT_EQ(ConstructionCounting::dtor_calls, 2); @@ -7658,7 +7661,10 @@ TEST(FlatTuple, ConstructorCalls) { // Move construction. ConstructionCounting::Reset(); - { FlatTuple tuple{ConstructionCounting{}}; } + { + FlatTuple tuple{ + testing::internal::FlatTupleConstructTag{}, ConstructionCounting{}}; + } EXPECT_EQ(ConstructionCounting::default_ctor_calls, 1); EXPECT_EQ(ConstructionCounting::dtor_calls, 2); EXPECT_EQ(ConstructionCounting::copy_ctor_calls, 0);