From ae88f39801549e6d553308e229f79255e7de9635 Mon Sep 17 00:00:00 2001 From: Steve Anton Date: Mon, 18 Mar 2019 19:22:03 +0000 Subject: [PATCH] Revert "Adding support for enum class in RTC_CHECK and RTC_LOG." This reverts commit 6b6f537e839ee32d72b69f1f6dc3747fbd12b3eb. Reason for revert: AddressSanitizer: stack-use-after-return third_party/webrtc/files/stable/webrtc/rtc_base/logging.cc:214:17 in rtc::LogMessage::~LogMessage() Original change's description: > Adding support for enum class in RTC_CHECK and RTC_LOG. > > Enum class types are by design not convertible to arithmetic types. > As a result they are currently not supported in RTC_CHECK and RTC_LOG. > The current workaround was to use something like RTC_CHECK(v1 == v2) > instead of RTC_CHECK_EQ(v1, v2). > This change adds support for any enum class type by converting it to the > underlying type. > > Bug: webrtc:10418 > Change-Id: I59e6608e6a97a4cc007c903f8e021a58d4c49ff8 > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/128202 > Reviewed-by: Karl Wiberg > Commit-Queue: Amit Hilbuch > Cr-Commit-Position: refs/heads/master@{#27166} TBR=kwiberg@webrtc.org,amithi@webrtc.org Change-Id: I515087dbbebd6bf8cbebd8f9944fd61a20f758db No-Presubmit: true No-Tree-Checks: true No-Try: true Bug: webrtc:10418 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/128540 Reviewed-by: Steve Anton Commit-Queue: Steve Anton Cr-Commit-Position: refs/heads/master@{#27168} --- rtc_base/checks.h | 34 ++++++++++++---------------------- rtc_base/logging.h | 34 ++++++++++++---------------------- rtc_base/logging_unittest.cc | 12 ------------ 3 files changed, 24 insertions(+), 56 deletions(-) diff --git a/rtc_base/checks.h b/rtc_base/checks.h index b351ad2e21..2694258fe5 100644 --- a/rtc_base/checks.h +++ b/rtc_base/checks.h @@ -168,16 +168,6 @@ inline Val MakeVal(const void* x) { return {x}; } -// The enum class types are not implicitly convertible to arithmetic types. -template < - typename T, - typename std::enable_if::value && - !std::is_arithmetic::value>::type* = nullptr> -inline decltype(MakeVal(std::declval::type>())) -MakeVal(T x) { - return {static_cast::type>(x)}; -} - // Ephemeral type that represents the result of the logging << operator. template class LogStreamer; @@ -186,18 +176,18 @@ class LogStreamer; template <> class LogStreamer<> final { public: - template ::value || - std::is_enum::value>::type* = nullptr> + template < + typename U, + typename std::enable_if::value>::type* = nullptr> RTC_FORCE_INLINE LogStreamer()))> operator<<( U arg) const { return LogStreamer()))>(MakeVal(arg), this); } - template ::value && - !std::is_enum::value>::type* = nullptr> + template < + typename U, + typename std::enable_if::value>::type* = nullptr> RTC_FORCE_INLINE LogStreamer()))> operator<<( const U& arg) const { return LogStreamer()))>(MakeVal(arg), @@ -232,18 +222,18 @@ class LogStreamer final { RTC_FORCE_INLINE LogStreamer(T arg, const LogStreamer* prior) : arg_(arg), prior_(prior) {} - template ::value || - std::is_enum::value>::type* = nullptr> + template < + typename U, + typename std::enable_if::value>::type* = nullptr> RTC_FORCE_INLINE LogStreamer())), T, Ts...> operator<<(U arg) const { return LogStreamer())), T, Ts...>( MakeVal(arg), this); } - template ::value && - !std::is_enum::value>::type* = nullptr> + template < + typename U, + typename std::enable_if::value>::type* = nullptr> RTC_FORCE_INLINE LogStreamer())), T, Ts...> operator<<(const U& arg) const { return LogStreamer())), T, Ts...>( diff --git a/rtc_base/logging.h b/rtc_base/logging.h index 3f48eeb0de..5cd4f72f22 100644 --- a/rtc_base/logging.h +++ b/rtc_base/logging.h @@ -248,16 +248,6 @@ inline Val MakeVal( return {x}; } -// The enum class types are not implicitly convertible to arithmetic types. -template < - typename T, - typename std::enable_if::value && - !std::is_arithmetic::value>::type* = nullptr> -inline decltype(MakeVal(std::declval::type>())) -MakeVal(T x) { - return {static_cast::type>(x)}; -} - #ifdef WEBRTC_ANDROID inline Val MakeVal( const LogMetadataTag& x) { @@ -295,18 +285,18 @@ class LogStreamer; template <> class LogStreamer<> final { public: - template ::value || - std::is_enum::value>::type* = nullptr> + template < + typename U, + typename std::enable_if::value>::type* = nullptr> RTC_FORCE_INLINE LogStreamer()))> operator<<( U arg) const { return LogStreamer()))>(MakeVal(arg), this); } - template ::value && - !std::is_enum::value>::type* = nullptr> + template < + typename U, + typename std::enable_if::value>::type* = nullptr> RTC_FORCE_INLINE LogStreamer()))> operator<<( const U& arg) const { return LogStreamer()))>(MakeVal(arg), @@ -328,18 +318,18 @@ class LogStreamer final { RTC_FORCE_INLINE LogStreamer(T arg, const LogStreamer* prior) : arg_(arg), prior_(prior) {} - template ::value || - std::is_enum::value>::type* = nullptr> + template < + typename U, + typename std::enable_if::value>::type* = nullptr> RTC_FORCE_INLINE LogStreamer())), T, Ts...> operator<<(U arg) const { return LogStreamer())), T, Ts...>( MakeVal(arg), this); } - template ::value && - !std::is_enum::value>::type* = nullptr> + template < + typename U, + typename std::enable_if::value>::type* = nullptr> RTC_FORCE_INLINE LogStreamer())), T, Ts...> operator<<(const U& arg) const { return LogStreamer())), T, Ts...>( diff --git a/rtc_base/logging_unittest.cc b/rtc_base/logging_unittest.cc index 4f05ac00cf..e49440dce1 100644 --- a/rtc_base/logging_unittest.cc +++ b/rtc_base/logging_unittest.cc @@ -368,16 +368,4 @@ TEST(LogTest, Perf) { << " total bytes logged: " << str.size(); } -TEST(LogTest, EnumsAreSupported) { - enum class TestEnum { kValue0 = 0, kValue1 = 1 }; - std::string str; - LogSinkImpl stream(&str); - LogMessage::AddLogToStream(&stream, LS_INFO); - RTC_LOG(LS_INFO) << "[" << TestEnum::kValue0 << "]"; - EXPECT_NE(std::string::npos, str.find("[0]")); - EXPECT_EQ(std::string::npos, str.find("[1]")); - RTC_LOG(LS_INFO) << "[" << TestEnum::kValue1 << "]"; - EXPECT_NE(std::string::npos, str.find("[1]")); -} - } // namespace rtc