From 3fa7f983c69f780378b4d1ad44d36030ca951ba6 Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Thu, 15 Dec 2022 11:50:08 -0800 Subject: [PATCH] Shut up a Clang warning. Clang warns on this pattern because it looks like the author might have meant to use the value of the first part of the comma operator, so it warns that it isn't being used. The cast here signals to Clang that this behavior is intentional. This was discovered while updating gmock in Android. Clang's -Wcomma warning is on by default with either -Wall or -Werror, so users of gmock with those on in combination with -Werror are unable to build without this fix. PiperOrigin-RevId: 495655990 Change-Id: Iaf27e2199669f5b6185a877738234e551b6b6556 --- googlemock/include/gmock/gmock-matchers.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/googlemock/include/gmock/gmock-matchers.h b/googlemock/include/gmock/gmock-matchers.h index 26fe8d2ea2..73be7c9973 100644 --- a/googlemock/include/gmock/gmock-matchers.h +++ b/googlemock/include/gmock/gmock-matchers.h @@ -4098,7 +4098,12 @@ class ArgsMatcherImpl : public MatcherInterface { const char* sep = ""; // Workaround spurious C4189 on MSVC<=15.7 when k is empty. (void)sep; - const char* dummy[] = {"", (*os << sep << "#" << k, sep = ", ")...}; + // The static_cast to void is needed to silence Clang's -Wcomma warning. + // This pattern looks suspiciously like we may have mismatched parentheses + // and may have been trying to use the first operation of the comma operator + // as a member of the array, so Clang warns that we may have made a mistake. + const char* dummy[] = { + "", (static_cast(*os << sep << "#" << k), sep = ", ")...}; (void)dummy; *os << ") "; }