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

Unified Diff: base/logging.h

Issue 2515283002: logging: Provide a specific MakeCheckOpValueString overload for functions (Closed)
Patch Set: Prevent the empty functions from being optimized Created 4 years, 1 month 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 | base/logging_unittest.cc » ('j') | base/logging_unittest.cc » ('J')
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 714545c02bb06ac7f1b31e8a007b671e6dc11d6d..22964cb3cfb546b55651d1912d12f364bf30e937 100644
--- a/base/logging.h
+++ b/base/logging.h
@@ -527,12 +527,24 @@ class CheckOpResult {
// it uses the definition for operator<<, with a few special cases below.
template <typename T>
inline typename std::enable_if<
- base::internal::SupportsOstreamOperator<const T&>::value,
+ base::internal::SupportsOstreamOperator<const T&>::value &&
+ !std::is_function<typename std::remove_pointer<T>::type>::value,
void>::type
MakeCheckOpValueString(std::ostream* os, const T& v) {
(*os) << v;
}
+// Provide an overload for functions and function pointers, which are otherwise
+// implicitly converted to bool (MSVC seems to be the exception) and produce
Nico 2016/11/23 18:09:26 This comment is a bit confusing as written. I'd re
+// unhelpful values.
+template <typename T>
+inline typename std::enable_if<
+ std::is_function<typename std::remove_pointer<T>::type>::value,
+ void>::type
+MakeCheckOpValueString(std::ostream* os, const T& v) {
+ (*os) << reinterpret_cast<const void*>(v);
+}
+
// We need overloads for enums that don't support operator<<.
// (i.e. scoped enums where no operator<< overload was declared).
template <typename T>
« no previous file with comments | « no previous file | base/logging_unittest.cc » ('j') | base/logging_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698