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

Side by Side Diff: base/logging.h

Issue 2692853008: Use universal references in templated analysis passthrough functions. (Closed)
Patch Set: memory => utility for std::forward Created 3 years, 10 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_LOGGING_H_ 5 #ifndef BASE_LOGGING_H_
6 #define BASE_LOGGING_H_ 6 #define BASE_LOGGING_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include <cassert> 10 #include <cassert>
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 291
292 // ANALYZER_ASSUME_TRUE(...) generates compiler-specific annotations which 292 // ANALYZER_ASSUME_TRUE(...) generates compiler-specific annotations which
293 // prevent the static analyzer from analyzing the code using hypothetical 293 // prevent the static analyzer from analyzing the code using hypothetical
294 // values that are asserted to be impossible. 294 // values that are asserted to be impossible.
295 // The value of the condition passed to ANALYZER_ASSUME_TRUE() is returned 295 // The value of the condition passed to ANALYZER_ASSUME_TRUE() is returned
296 // directly. 296 // directly.
297 #if defined(__clang_analyzer__) 297 #if defined(__clang_analyzer__)
298 298
299 inline void AnalyzerNoReturn() __attribute__((analyzer_noreturn)) {} 299 inline void AnalyzerNoReturn() __attribute__((analyzer_noreturn)) {}
300 300
301 // |arg| is a universal reference for compatibility with lvalue and rvalue
302 // arguments.
301 template <typename TVal> 303 template <typename TVal>
302 inline constexpr TVal AnalysisAssumeTrue(TVal arg) { 304 inline constexpr TVal&& AnalysisAssumeTrue(TVal&& arg) {
303 if (!arg) { 305 if (!arg) {
304 AnalyzerNoReturn(); 306 AnalyzerNoReturn();
305 } 307 }
306 return arg; 308 return std::forward<TVal>(arg);
307 } 309 }
308 310
309 #define ANALYZER_ASSUME_TRUE(val) ::logging::AnalysisAssumeTrue(val) 311 #define ANALYZER_ASSUME_TRUE(val) ::logging::AnalysisAssumeTrue(val)
310 312
311 #elif defined(_PREFAST_) && defined(OS_WIN) 313 #elif defined(_PREFAST_) && defined(OS_WIN)
312 314
315 // |arg| is a universal reference for compatibility with lvalue and rvalue
316 // arguments.
313 template <typename TVal> 317 template <typename TVal>
314 inline constexpr TVal AnalysisAssumeTrue(TVal arg) { 318 inline constexpr TVal&& AnalysisAssumeTrue(TVal&& arg) {
315 __analysis_assume(!!arg); 319 __analysis_assume(!!arg);
316 return arg; 320 return std::forward<TVal>(arg);
317 } 321 }
318 322
319 #define ANALYZER_ASSUME_TRUE(val) ::logging::AnalysisAssumeTrue(val) 323 #define ANALYZER_ASSUME_TRUE(val) ::logging::AnalysisAssumeTrue(val)
320 324
321 #else // !_PREFAST_ & !__clang_analyzer__ 325 #else // !_PREFAST_ & !__clang_analyzer__
322 326
323 #define ANALYZER_ASSUME_TRUE(val) (val) 327 #define ANALYZER_ASSUME_TRUE(val) (val)
324 328
325 #endif // !_PREFAST_ & !__clang_analyzer__ 329 #endif // !_PREFAST_ & !__clang_analyzer__
326 330
(...skipping 724 matching lines...) Expand 10 before | Expand all | Expand 10 after
1051 #elif NOTIMPLEMENTED_POLICY == 5 1055 #elif NOTIMPLEMENTED_POLICY == 5
1052 #define NOTIMPLEMENTED() do {\ 1056 #define NOTIMPLEMENTED() do {\
1053 static bool logged_once = false;\ 1057 static bool logged_once = false;\
1054 LOG_IF(ERROR, !logged_once) << NOTIMPLEMENTED_MSG;\ 1058 LOG_IF(ERROR, !logged_once) << NOTIMPLEMENTED_MSG;\
1055 logged_once = true;\ 1059 logged_once = true;\
1056 } while(0);\ 1060 } while(0);\
1057 EAT_STREAM_PARAMETERS 1061 EAT_STREAM_PARAMETERS
1058 #endif 1062 #endif
1059 1063
1060 #endif // BASE_LOGGING_H_ 1064 #endif // BASE_LOGGING_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