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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | base/logging_unittest.cc » ('j') | base/logging_unittest.cc » ('J')
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 509 matching lines...) Expand 10 before | Expand all | Expand 10 after
520 ; \ 520 ; \
521 else \ 521 else \
522 ::logging::LogMessage(__FILE__, __LINE__, true_if_passed.message()).stream() 522 ::logging::LogMessage(__FILE__, __LINE__, true_if_passed.message()).stream()
523 523
524 #endif // !(OFFICIAL_BUILD && NDEBUG) 524 #endif // !(OFFICIAL_BUILD && NDEBUG)
525 525
526 // This formats a value for a failing CHECK_XX statement. Ordinarily, 526 // This formats a value for a failing CHECK_XX statement. Ordinarily,
527 // it uses the definition for operator<<, with a few special cases below. 527 // it uses the definition for operator<<, with a few special cases below.
528 template <typename T> 528 template <typename T>
529 inline typename std::enable_if< 529 inline typename std::enable_if<
530 base::internal::SupportsOstreamOperator<const T&>::value, 530 base::internal::SupportsOstreamOperator<const T&>::value &&
531 !std::is_function<typename std::remove_pointer<T>::type>::value,
531 void>::type 532 void>::type
532 MakeCheckOpValueString(std::ostream* os, const T& v) { 533 MakeCheckOpValueString(std::ostream* os, const T& v) {
533 (*os) << v; 534 (*os) << v;
534 } 535 }
535 536
537 // Provide an overload for functions and function pointers, which are otherwise
538 // 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
539 // unhelpful values.
540 template <typename T>
541 inline typename std::enable_if<
542 std::is_function<typename std::remove_pointer<T>::type>::value,
543 void>::type
544 MakeCheckOpValueString(std::ostream* os, const T& v) {
545 (*os) << reinterpret_cast<const void*>(v);
546 }
547
536 // We need overloads for enums that don't support operator<<. 548 // We need overloads for enums that don't support operator<<.
537 // (i.e. scoped enums where no operator<< overload was declared). 549 // (i.e. scoped enums where no operator<< overload was declared).
538 template <typename T> 550 template <typename T>
539 inline typename std::enable_if< 551 inline typename std::enable_if<
540 !base::internal::SupportsOstreamOperator<const T&>::value && 552 !base::internal::SupportsOstreamOperator<const T&>::value &&
541 std::is_enum<T>::value, 553 std::is_enum<T>::value,
542 void>::type 554 void>::type
543 MakeCheckOpValueString(std::ostream* os, const T& v) { 555 MakeCheckOpValueString(std::ostream* os, const T& v) {
544 (*os) << static_cast<typename base::underlying_type<T>::type>(v); 556 (*os) << static_cast<typename base::underlying_type<T>::type>(v);
545 } 557 }
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after
988 #elif NOTIMPLEMENTED_POLICY == 5 1000 #elif NOTIMPLEMENTED_POLICY == 5
989 #define NOTIMPLEMENTED() do {\ 1001 #define NOTIMPLEMENTED() do {\
990 static bool logged_once = false;\ 1002 static bool logged_once = false;\
991 LOG_IF(ERROR, !logged_once) << NOTIMPLEMENTED_MSG;\ 1003 LOG_IF(ERROR, !logged_once) << NOTIMPLEMENTED_MSG;\
992 logged_once = true;\ 1004 logged_once = true;\
993 } while(0);\ 1005 } while(0);\
994 EAT_STREAM_PARAMETERS 1006 EAT_STREAM_PARAMETERS
995 #endif 1007 #endif
996 1008
997 #endif // BASE_LOGGING_H_ 1009 #endif // BASE_LOGGING_H_
OLDNEW
« 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