From 7d7e750850c65099e49cc1a1aac94a79a914bba7 Mon Sep 17 00:00:00 2001 From: Derek Mauro Date: Tue, 6 Jan 2026 10:36:52 -0800 Subject: [PATCH] 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 --- googlemock/include/gmock/gmock-spec-builders.h | 6 +++--- .../include/gmock/internal/gmock-internal-utils.h | 11 +++-------- googlemock/src/gmock-internal-utils.cc | 2 +- 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/googlemock/include/gmock/gmock-spec-builders.h b/googlemock/include/gmock/gmock-spec-builders.h index f1c979d6..5cb10c09 100644 --- a/googlemock/include/gmock/gmock-spec-builders.h +++ b/googlemock/include/gmock/gmock-spec-builders.h @@ -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) \ diff --git a/googlemock/include/gmock/internal/gmock-internal-utils.h b/googlemock/include/gmock/internal/gmock-internal-utils.h index cf05d76f..2e746f82 100644 --- a/googlemock/include/gmock/internal/gmock-internal-utils.h +++ b/googlemock/include/gmock/internal/gmock-internal-utils.h @@ -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() is usable as an expression of type T, but will terminate // the program with an assertion failure if actually run. This is useful diff --git a/googlemock/src/gmock-internal-utils.cc b/googlemock/src/gmock-internal-utils.cc index ceee329a..c4aca256 100644 --- a/googlemock/src/gmock-internal-utils.cc +++ b/googlemock/src/gmock-internal-utils.cc @@ -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(