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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef BASE_COMPILER_SPECIFIC_H_ 5 #ifndef BASE_COMPILER_SPECIFIC_H_
6 #define BASE_COMPILER_SPECIFIC_H_ 6 #define BASE_COMPILER_SPECIFIC_H_
7 7
8 #include "build/build_config.h" 8 #include "build/build_config.h"
9 9
10 #if defined(COMPILER_MSVC) 10 #if defined(COMPILER_MSVC)
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 #define MSVC_SUPPRESS_WARNING(n) 64 #define MSVC_SUPPRESS_WARNING(n)
65 #define MSVC_PUSH_DISABLE_WARNING(n) 65 #define MSVC_PUSH_DISABLE_WARNING(n)
66 #define MSVC_PUSH_WARNING_LEVEL(n) 66 #define MSVC_PUSH_WARNING_LEVEL(n)
67 #define MSVC_POP_WARNING() 67 #define MSVC_POP_WARNING()
68 #define MSVC_DISABLE_OPTIMIZE() 68 #define MSVC_DISABLE_OPTIMIZE()
69 #define MSVC_ENABLE_OPTIMIZE() 69 #define MSVC_ENABLE_OPTIMIZE()
70 #define NON_EXPORTED_BASE(code) code 70 #define NON_EXPORTED_BASE(code) code
71 71
72 #endif // COMPILER_MSVC 72 #endif // COMPILER_MSVC
73 73
74
75 // Annotate a variable indicating it's ok if the variable is not used. 74 // Annotate a variable indicating it's ok if the variable is not used.
76 // (Typically used to silence a compiler warning when the assignment 75 // (Typically used to silence a compiler warning when the assignment
77 // is important for some other reason.) 76 // is important for some other reason.)
78 // Use like: 77 // Use like:
79 // int x = ...; 78 // int x = ...;
80 // ALLOW_UNUSED_LOCAL(x); 79 // ALLOW_UNUSED_LOCAL(x);
80 //
81 // The common-case implementation references |x| in such a way that it's never
82 // evaluated. Static analysis builds still see this as not referencing |x|, so
83 // in such cases we reference it directly to make the compiler happy, at the
84 // risk of unintended side effects.
85 #if defined(__clang_analyzer__)
86
87 #define ALLOW_UNUSED_LOCAL(x) (void)x
88
89 #else // !defined(__clang_analyzer__)
90
81 #define ALLOW_UNUSED_LOCAL(x) false ? (void)x : (void)0 91 #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
82 92
93 #endif // defined(__clang_analyzer__)
94
83 // Annotate a typedef or function indicating it's ok if it's not used. 95 // Annotate a typedef or function indicating it's ok if it's not used.
84 // Use like: 96 // Use like:
85 // typedef Foo Bar ALLOW_UNUSED_TYPE; 97 // typedef Foo Bar ALLOW_UNUSED_TYPE;
86 #if defined(COMPILER_GCC) || defined(__clang__) 98 #if defined(COMPILER_GCC) || defined(__clang__)
87 #define ALLOW_UNUSED_TYPE __attribute__((unused)) 99 #define ALLOW_UNUSED_TYPE __attribute__((unused))
88 #else 100 #else
89 #define ALLOW_UNUSED_TYPE 101 #define ALLOW_UNUSED_TYPE
90 #endif 102 #endif
91 103
92 // Annotate a function indicating it should not be inlined. 104 // Annotate a function indicating it should not be inlined.
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 236
225 // Compiler feature-detection. 237 // Compiler feature-detection.
226 // clang.llvm.org/docs/LanguageExtensions.html#has-feature-and-has-extension 238 // clang.llvm.org/docs/LanguageExtensions.html#has-feature-and-has-extension
227 #if defined(__has_feature) 239 #if defined(__has_feature)
228 #define HAS_FEATURE(FEATURE) __has_feature(FEATURE) 240 #define HAS_FEATURE(FEATURE) __has_feature(FEATURE)
229 #else 241 #else
230 #define HAS_FEATURE(FEATURE) 0 242 #define HAS_FEATURE(FEATURE) 0
231 #endif 243 #endif
232 244
233 #endif // BASE_COMPILER_SPECIFIC_H_ 245 #endif // BASE_COMPILER_SPECIFIC_H_
OLDNEW
« 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