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

Unified 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 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/logging.h
diff --git a/base/logging.h b/base/logging.h
index c0ebaf92bd3da3da67fa467cea0399542790debd..a3efc7e38bffa0f499a50ae4c7cc30b6ecbe9fd4 100644
--- a/base/logging.h
+++ b/base/logging.h
@@ -298,6 +298,8 @@ BASE_EXPORT LogMessageHandlerFunction GetLogMessageHandler();
inline void AnalyzerNoReturn() __attribute__((analyzer_noreturn)) {}
+// A universal reference is used for compatibility with lvalue and rvalue
+// argument passing.
template <typename TVal>
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.
if (!arg) {
@@ -310,8 +312,10 @@ inline constexpr TVal AnalysisAssumeTrue(TVal arg) {
#elif defined(_PREFAST_) && defined(OS_WIN)
+// A universal reference is used for compatibility with lvalue and rvalue
+// argument passing.
template <typename TVal>
-inline constexpr TVal AnalysisAssumeTrue(TVal arg) {
+inline constexpr TVal AnalysisAssumeTrue(TVal&& arg) {
__analysis_assume(!!arg);
return arg;
}
@@ -628,16 +632,20 @@ std::string* MakeCheckOpString<std::string, std::string>(
// The (int, int) specialization works around the issue that the compiler
// will not instantiate the template version of the function on values of
// unnamed enum type - see comment below.
-#define DEFINE_CHECK_OP_IMPL(name, op) \
- template <class t1, class t2> \
- inline std::string* Check##name##Impl(const t1& v1, const t2& v2, \
- const char* names) { \
- if (v1 op v2) return NULL; \
- else return ::logging::MakeCheckOpString(v1, v2, names); \
- } \
+#define DEFINE_CHECK_OP_IMPL(name, op) \
+ template <class t1, class t2> \
+ inline std::string* Check##name##Impl(const t1& v1, const t2& v2, \
+ const char* names) { \
+ if (ANALYZER_ASSUME_TRUE(v1 op v2)) \
+ return NULL; \
+ else \
+ return ::logging::MakeCheckOpString(v1, v2, names); \
+ } \
inline std::string* Check##name##Impl(int v1, int v2, const char* names) { \
- if (v1 op v2) return NULL; \
- else return ::logging::MakeCheckOpString(v1, v2, names); \
+ if (ANALYZER_ASSUME_TRUE(v1 op v2)) \
+ return NULL; \
+ else \
+ return ::logging::MakeCheckOpString(v1, v2, names); \
}
DEFINE_CHECK_OP_IMPL(EQ, ==)
DEFINE_CHECK_OP_IMPL(NE, !=)
« 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