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

Side by Side Diff: base/logging.h

Issue 2653073002: Make sure DCHECK compiles out completely if DCHECKS aren't enabled. (Closed)
Patch Set: Really truly fix build. Created 3 years, 11 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 710 matching lines...) Expand 10 before | Expand all | Expand 10 after
721 LAZY_STREAM(LOG_STREAM(DCHECK), false) \ 721 LAZY_STREAM(LOG_STREAM(DCHECK), false) \
722 << "Check failed: " #condition ". " 722 << "Check failed: " #condition ". "
723 723
724 #define DPCHECK(condition) \ 724 #define DPCHECK(condition) \
725 __analysis_assume(!!(condition)), \ 725 __analysis_assume(!!(condition)), \
726 LAZY_STREAM(PLOG_STREAM(DCHECK), false) \ 726 LAZY_STREAM(PLOG_STREAM(DCHECK), false) \
727 << "Check failed: " #condition ". " 727 << "Check failed: " #condition ". "
728 728
729 #else // _PREFAST_ 729 #else // _PREFAST_
730 730
731 #define DCHECK(condition) \ 731 #if DCHECK_IS_ON()
732 LAZY_STREAM(LOG_STREAM(DCHECK), DCHECK_IS_ON() ? !(condition) : false) \ 732
733 #define DCHECK(condition) \
734 LAZY_STREAM(LOG_STREAM(DCHECK), !(condition)) \
735 << "Check failed: " #condition ". "
736 #define DPCHECK(condition) \
737 LAZY_STREAM(PLOG_STREAM(DCHECK), !(condition)) \
733 << "Check failed: " #condition ". " 738 << "Check failed: " #condition ". "
734 739
735 #define DPCHECK(condition) \ 740 #else // DCHECK_IS_ON()
736 LAZY_STREAM(PLOG_STREAM(DCHECK), DCHECK_IS_ON() ? !(condition) : false) \ 741
737 << "Check failed: " #condition ". " 742 #define DCHECK(condition) EAT_STREAM_PARAMETERS << !(condition)
743 #define DPCHECK(condition) EAT_STREAM_PARAMETERS << !(condition)
744
745 #endif // DCHECK_IS_ON()
738 746
739 #endif // _PREFAST_ 747 #endif // _PREFAST_
740 748
741 // Helper macro for binary operators. 749 // Helper macro for binary operators.
742 // Don't use this macro directly in your code, use DCHECK_EQ et al below. 750 // Don't use this macro directly in your code, use DCHECK_EQ et al below.
743 // The 'switch' is used to prevent the 'else' from being ambiguous when the 751 // The 'switch' is used to prevent the 'else' from being ambiguous when the
744 // macro is used in an 'if' clause such as: 752 // macro is used in an 'if' clause such as:
745 // if (a == 1) 753 // if (a == 1)
746 // DCHECK_EQ(2, a); 754 // DCHECK_EQ(2, a);
755 #if DCHECK_IS_ON()
756
747 #define DCHECK_OP(name, op, val1, val2) \ 757 #define DCHECK_OP(name, op, val1, val2) \
748 switch (0) case 0: default: \ 758 switch (0) case 0: default: \
749 if (::logging::CheckOpResult true_if_passed = \ 759 if (::logging::CheckOpResult true_if_passed = \
750 DCHECK_IS_ON() ? \ 760 DCHECK_IS_ON() ? \
751 ::logging::Check##name##Impl((val1), (val2), \ 761 ::logging::Check##name##Impl((val1), (val2), \
752 #val1 " " #op " " #val2) : nullptr) \ 762 #val1 " " #op " " #val2) : nullptr) \
753 ; \ 763 ; \
754 else \ 764 else \
755 ::logging::LogMessage(__FILE__, __LINE__, ::logging::LOG_DCHECK, \ 765 ::logging::LogMessage(__FILE__, __LINE__, ::logging::LOG_DCHECK, \
756 true_if_passed.message()).stream() 766 true_if_passed.message()).stream()
757 767
768 #else // DCHECK_IS_ON()
769
770 #define DCHECK_OP(name, op, val1, val2) \
771 EAT_STREAM_PARAMETERS << (::logging::MakeCheckOpValueString( \
772 ::logging::g_swallow_stream, val1), \
773 ::logging::MakeCheckOpValueString( \
774 ::logging::g_swallow_stream, val2), \
Wez 2017/01/25 01:57:24 nit: Add a comment to clarify why we're doing this
dcheng 2017/01/25 03:11:58 Done.
775 (val1)op(val2))
776
777 #endif // DCHECK_IS_ON()
778
758 // Equality/Inequality checks - compare two values, and log a 779 // Equality/Inequality checks - compare two values, and log a
759 // LOG_DCHECK message including the two values when the result is not 780 // LOG_DCHECK message including the two values when the result is not
760 // as expected. The values must have operator<<(ostream, ...) 781 // as expected. The values must have operator<<(ostream, ...)
761 // defined. 782 // defined.
762 // 783 //
763 // You may append to the error message like so: 784 // You may append to the error message like so:
764 // DCHECK_NE(1, 2) << "The world must be ending!"; 785 // DCHECK_NE(1, 2) << "The world must be ending!";
765 // 786 //
766 // We are very careful to ensure that each argument is evaluated exactly 787 // We are very careful to ensure that each argument is evaluated exactly
767 // once, and that anything which is legal to pass as a function argument is 788 // once, and that anything which is legal to pass as a function argument is
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
1018 #elif NOTIMPLEMENTED_POLICY == 5 1039 #elif NOTIMPLEMENTED_POLICY == 5
1019 #define NOTIMPLEMENTED() do {\ 1040 #define NOTIMPLEMENTED() do {\
1020 static bool logged_once = false;\ 1041 static bool logged_once = false;\
1021 LOG_IF(ERROR, !logged_once) << NOTIMPLEMENTED_MSG;\ 1042 LOG_IF(ERROR, !logged_once) << NOTIMPLEMENTED_MSG;\
1022 logged_once = true;\ 1043 logged_once = true;\
1023 } while(0);\ 1044 } while(0);\
1024 EAT_STREAM_PARAMETERS 1045 EAT_STREAM_PARAMETERS
1025 #endif 1046 #endif
1026 1047
1027 #endif // BASE_LOGGING_H_ 1048 #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