Skip to content

Commit

Permalink
Resolve an issue where the resolution of operator<< overloads would…
Browse files Browse the repository at this point in the history
… attempt to instantiate the incomplete `testing::internal::Secret` type.

PiperOrigin-RevId: 543799815
Change-Id: Ic0a4f48d825bef26cb8cc74d8a0117b3a5ef3f14
  • Loading branch information
Abseil Team authored and copybara-github committed Jun 27, 2023
1 parent 8e32de8 commit f269e15
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
6 changes: 4 additions & 2 deletions googletest/include/gtest/internal/gtest-port.h
Original file line number Diff line number Diff line change
Expand Up @@ -925,9 +925,11 @@ using std::tuple_size;
namespace internal {

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

// A helper for suppressing warnings on constant condition. It just
// returns 'condition'.
Expand Down
16 changes: 16 additions & 0 deletions googletest/test/gtest_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,27 @@ TEST(CommandLineFlagsTest, CanBeAccessedInCodeOnceGTestHIsIncluded) {
#include <string>
#include <type_traits>
#include <unordered_set>
#include <utility>
#include <vector>

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

struct ConvertibleGlobalType {
// The inner enable_if is to ensure invoking is_constructible doesn't fail.
// The outer enable_if is to ensure the overload resolution doesn't encounter
// an ambiguity.
template <
class T,
std::enable_if_t<
false, std::enable_if_t<std::is_constructible<T>::value, int>> = 0>
operator T() const; // NOLINT(google-explicit-constructor)
};
void operator<<(ConvertibleGlobalType&, int);
static_assert(sizeof(decltype(std::declval<ConvertibleGlobalType&>()
<< 1)(*)()) > 0,
"error in operator<< overload resolution");

namespace testing {
namespace internal {

Expand Down

0 comments on commit f269e15

Please sign in to comment.