Fix "error: standard attributes in middle of decl-specifiers"

Between the friend declaration, visibility declaration, and
attribute placement rules, compilers can't seem to agree on the
how to write this, so I switched to a static factory function.

Fixes https://github.com/google/googletest/issues/4881

PiperOrigin-RevId: 852842303
Change-Id: I7fe737819abf05ea2911693f8d93683446e326cc
This commit is contained in:
Derek Mauro 2026-01-06 10:36:52 -08:00 committed by Copybara-Service
parent 76cd89bcf1
commit 7d7e750850
3 changed files with 7 additions and 12 deletions

View File

@ -2132,9 +2132,9 @@ GTEST_DISABLE_MSC_WARNINGS_POP_() // 4251
// second argument is an internal type derived from the method signature. The
// failure to disambiguate two overloads of this method in the ON_CALL statement
// is how we block callers from setting expectations on overloaded methods.
#define GMOCK_ON_CALL_IMPL_(mock_expr, Setter, call) \
((mock_expr).gmock_##call)(::testing::internal::GetWithoutMatchers(), \
nullptr) \
#define GMOCK_ON_CALL_IMPL_(mock_expr, Setter, call) \
((mock_expr).gmock_##call)(::testing::internal::WithoutMatchers::Get(), \
nullptr) \
.Setter(__FILE__, __LINE__, #mock_expr, #call)
#define ON_CALL(obj, call) \

View File

@ -299,15 +299,10 @@ GTEST_API_ void Log(LogSeverity severity, const std::string& message,
class [[nodiscard]] WithoutMatchers {
private:
WithoutMatchers() = default;
friend
#ifdef GTEST_OS_WINDOWS
GTEST_API_
#endif
WithoutMatchers GetWithoutMatchers();
};
// Internal use only: access the singleton instance of WithoutMatchers.
GTEST_API_ WithoutMatchers GetWithoutMatchers();
public:
GTEST_API_ static WithoutMatchers Get();
};
// Invalid<T>() is usable as an expression of type T, but will terminate
// the program with an assertion failure if actually run. This is useful

View File

@ -188,7 +188,7 @@ GTEST_API_ void Log(LogSeverity severity, const std::string& message,
std::cout << ::std::flush;
}
GTEST_API_ WithoutMatchers GetWithoutMatchers() { return WithoutMatchers(); }
GTEST_API_ WithoutMatchers WithoutMatchers::Get() { return WithoutMatchers(); }
GTEST_API_ void IllegalDoDefault(const char* file, int line) {
internal::Assert(