Skip to content

Commit f269e15

Browse files
Abseil Teamcopybara-github
Abseil Team
authored andcommitted
Resolve an issue where the resolution of operator<< overloads would attempt to instantiate the incomplete testing::internal::Secret type.
PiperOrigin-RevId: 543799815 Change-Id: Ic0a4f48d825bef26cb8cc74d8a0117b3a5ef3f14
1 parent 8e32de8 commit f269e15

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

googletest/include/gtest/internal/gtest-port.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -925,9 +925,11 @@ using std::tuple_size;
925925
namespace internal {
926926

927927
// A secret type that Google Test users don't know about. It has no
928-
// definition on purpose. Therefore it's impossible to create a
928+
// accessible constructors on purpose. Therefore it's impossible to create a
929929
// Secret object, which is what we want.
930-
class Secret;
930+
class Secret {
931+
Secret(const Secret&) = delete;
932+
};
931933

932934
// A helper for suppressing warnings on constant condition. It just
933935
// returns 'condition'.

googletest/test/gtest_unittest.cc

+16
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,27 @@ TEST(CommandLineFlagsTest, CanBeAccessedInCodeOnceGTestHIsIncluded) {
6767
#include <string>
6868
#include <type_traits>
6969
#include <unordered_set>
70+
#include <utility>
7071
#include <vector>
7172

7273
#include "gtest/gtest-spi.h"
7374
#include "src/gtest-internal-inl.h"
7475

76+
struct ConvertibleGlobalType {
77+
// The inner enable_if is to ensure invoking is_constructible doesn't fail.
78+
// The outer enable_if is to ensure the overload resolution doesn't encounter
79+
// an ambiguity.
80+
template <
81+
class T,
82+
std::enable_if_t<
83+
false, std::enable_if_t<std::is_constructible<T>::value, int>> = 0>
84+
operator T() const; // NOLINT(google-explicit-constructor)
85+
};
86+
void operator<<(ConvertibleGlobalType&, int);
87+
static_assert(sizeof(decltype(std::declval<ConvertibleGlobalType&>()
88+
<< 1)(*)()) > 0,
89+
"error in operator<< overload resolution");
90+
7591
namespace testing {
7692
namespace internal {
7793

0 commit comments

Comments
 (0)