Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(858)

Unified Diff: base/compiler_specific.h

Issue 2838713002: Simplify ALLOW_UNUSED_LOCAL to use (void)x directly instead of conditionally. (Closed)
Patch Set: Use pkasting's comment suggestion Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/compiler_specific.h
diff --git a/base/compiler_specific.h b/base/compiler_specific.h
index 0f4c058b3be43963d76c23b0b3b8ec89fc8b3767..287e51184a3a902f3a495e284fc642a5b3192d88 100644
--- a/base/compiler_specific.h
+++ b/base/compiler_specific.h
@@ -71,15 +71,27 @@
#endif // COMPILER_MSVC
-
// Annotate a variable indicating it's ok if the variable is not used.
// (Typically used to silence a compiler warning when the assignment
// is important for some other reason.)
// Use like:
// int x = ...;
// ALLOW_UNUSED_LOCAL(x);
+//
+// The common-case implementation references |x| in such a way that it's never
+// evaluated. Static analysis builds still see this as not referencing |x|, so
+// in such cases we reference it directly to make the compiler happy, at the
+// risk of unintended side effects.
+#if defined(__clang_analyzer__)
+
+#define ALLOW_UNUSED_LOCAL(x) (void)x
+
+#else // !defined(__clang_analyzer__)
+
#define ALLOW_UNUSED_LOCAL(x) false ? (void)x : (void)0
Nico 2017/04/25 15:48:52 What was the problem with making this use `(void)x
Kevin Marshall 2017/04/25 17:17:31 When I asked pkasting (author of the original #def
+#endif // defined(__clang_analyzer__)
+
// Annotate a typedef or function indicating it's ok if it's not used.
// Use like:
// typedef Foo Bar ALLOW_UNUSED_TYPE;
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698