Skip to content

Commit 3fa7f98

Browse files
Abseil Teamcopybara-github
Abseil Team
authored andcommitted
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
1 parent 41fe6be commit 3fa7f98

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

googlemock/include/gmock/gmock-matchers.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4098,7 +4098,12 @@ class ArgsMatcherImpl : public MatcherInterface<ArgsTuple> {
40984098
const char* sep = "";
40994099
// Workaround spurious C4189 on MSVC<=15.7 when k is empty.
41004100
(void)sep;
4101-
const char* dummy[] = {"", (*os << sep << "#" << k, sep = ", ")...};
4101+
// The static_cast to void is needed to silence Clang's -Wcomma warning.
4102+
// This pattern looks suspiciously like we may have mismatched parentheses
4103+
// and may have been trying to use the first operation of the comma operator
4104+
// as a member of the array, so Clang warns that we may have made a mistake.
4105+
const char* dummy[] = {
4106+
"", (static_cast<void>(*os << sep << "#" << k), sep = ", ")...};
41024107
(void)dummy;
41034108
*os << ") ";
41044109
}

0 commit comments

Comments
 (0)