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

Side by Side Diff: base/logging.h

Issue 2692853008: Use universal references in templated analysis passthrough functions. (Closed)
Patch Set: danakj #2 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 // A universal reference is used for compatibility with lvalue and rvalue
302 // argument passing.
301 template <typename TVal> 303 template <typename TVal>
302 inline constexpr TVal AnalysisAssumeTrue(TVal arg) { 304 inline constexpr TVal AnalysisAssumeTrue(TVal arg) {
danakj 2017/02/14 21:10:10 dropped the && here
Kevin M 2017/02/14 22:07:48 Done.
303 if (!arg) { 305 if (!arg) {
304 AnalyzerNoReturn(); 306 AnalyzerNoReturn();
305 } 307 }
306 return arg; 308 return 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 // A universal reference is used for compatibility with lvalue and rvalue
316 // argument passing.
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 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
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
621 std::string* MakeCheckOpString<unsigned int, unsigned long>( 625 std::string* MakeCheckOpString<unsigned int, unsigned long>(
622 const unsigned int&, const unsigned long&, const char* names); 626 const unsigned int&, const unsigned long&, const char* names);
623 extern template BASE_EXPORT 627 extern template BASE_EXPORT
624 std::string* MakeCheckOpString<std::string, std::string>( 628 std::string* MakeCheckOpString<std::string, std::string>(
625 const std::string&, const std::string&, const char* name); 629 const std::string&, const std::string&, const char* name);
626 630
627 // Helper functions for CHECK_OP macro. 631 // Helper functions for CHECK_OP macro.
628 // The (int, int) specialization works around the issue that the compiler 632 // The (int, int) specialization works around the issue that the compiler
629 // will not instantiate the template version of the function on values of 633 // will not instantiate the template version of the function on values of
630 // unnamed enum type - see comment below. 634 // unnamed enum type - see comment below.
631 #define DEFINE_CHECK_OP_IMPL(name, op) \ 635 #define DEFINE_CHECK_OP_IMPL(name, op) \
632 template <class t1, class t2> \ 636 template <class t1, class t2> \
633 inline std::string* Check##name##Impl(const t1& v1, const t2& v2, \ 637 inline std::string* Check##name##Impl(const t1& v1, const t2& v2, \
634 const char* names) { \ 638 const char* names) { \
635 if (v1 op v2) return NULL; \ 639 if (ANALYZER_ASSUME_TRUE(v1 op v2)) \
636 else return ::logging::MakeCheckOpString(v1, v2, names); \ 640 return NULL; \
637 } \ 641 else \
642 return ::logging::MakeCheckOpString(v1, v2, names); \
643 } \
638 inline std::string* Check##name##Impl(int v1, int v2, const char* names) { \ 644 inline std::string* Check##name##Impl(int v1, int v2, const char* names) { \
639 if (v1 op v2) return NULL; \ 645 if (ANALYZER_ASSUME_TRUE(v1 op v2)) \
640 else return ::logging::MakeCheckOpString(v1, v2, names); \ 646 return NULL; \
647 else \
648 return ::logging::MakeCheckOpString(v1, v2, names); \
641 } 649 }
642 DEFINE_CHECK_OP_IMPL(EQ, ==) 650 DEFINE_CHECK_OP_IMPL(EQ, ==)
643 DEFINE_CHECK_OP_IMPL(NE, !=) 651 DEFINE_CHECK_OP_IMPL(NE, !=)
644 DEFINE_CHECK_OP_IMPL(LE, <=) 652 DEFINE_CHECK_OP_IMPL(LE, <=)
645 DEFINE_CHECK_OP_IMPL(LT, < ) 653 DEFINE_CHECK_OP_IMPL(LT, < )
646 DEFINE_CHECK_OP_IMPL(GE, >=) 654 DEFINE_CHECK_OP_IMPL(GE, >=)
647 DEFINE_CHECK_OP_IMPL(GT, > ) 655 DEFINE_CHECK_OP_IMPL(GT, > )
648 #undef DEFINE_CHECK_OP_IMPL 656 #undef DEFINE_CHECK_OP_IMPL
649 657
650 #define CHECK_EQ(val1, val2) CHECK_OP(EQ, ==, val1, val2) 658 #define CHECK_EQ(val1, val2) CHECK_OP(EQ, ==, val1, val2)
(...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after
1051 #elif NOTIMPLEMENTED_POLICY == 5 1059 #elif NOTIMPLEMENTED_POLICY == 5
1052 #define NOTIMPLEMENTED() do {\ 1060 #define NOTIMPLEMENTED() do {\
1053 static bool logged_once = false;\ 1061 static bool logged_once = false;\
1054 LOG_IF(ERROR, !logged_once) << NOTIMPLEMENTED_MSG;\ 1062 LOG_IF(ERROR, !logged_once) << NOTIMPLEMENTED_MSG;\
1055 logged_once = true;\ 1063 logged_once = true;\
1056 } while(0);\ 1064 } while(0);\
1057 EAT_STREAM_PARAMETERS 1065 EAT_STREAM_PARAMETERS
1058 #endif 1066 #endif
1059 1067
1060 #endif // BASE_LOGGING_H_ 1068 #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