From: Adam Simpkins <simpkins@fb.com>
Date: Wed, 5 Jul 2017 17:48:49 +0000 (-0700)
Subject: logging: fix compiler compatibility for one more constexpr function
X-Git-Tag: v2017.07.10.00~8
X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=7b116ffe3b116ffc3c2089ca0b864ca7ebb1d28c;p=folly.git

logging: fix compiler compatibility for one more constexpr function

Summary:
Update LogLevel's operator+() to consist only of a single return statement.
This is required for pre-C++14 compiler support.

Reviewed By: yfeldblum

Differential Revision: D5368256

fbshipit-source-id: 9ecbcde5edd1d0b3e7580d6263ad926e44908219
---

diff --git a/folly/experimental/logging/LogLevel.h b/folly/experimental/logging/LogLevel.h
index 75f401b1..a3e0e34a 100644
--- a/folly/experimental/logging/LogLevel.h
+++ b/folly/experimental/logging/LogLevel.h
@@ -84,12 +84,11 @@ enum class LogLevel : uint32_t {
  * adjusted log level values.
  */
 inline constexpr LogLevel operator+(LogLevel level, uint32_t value) {
-  auto newValue = static_cast<uint32_t>(level) + value;
   // Cap the result at LogLevel::MAX_LEVEL
-  if (newValue > static_cast<uint32_t>(LogLevel::MAX_LEVEL)) {
-    return LogLevel::MAX_LEVEL;
-  }
-  return static_cast<LogLevel>(newValue);
+  return ((static_cast<uint32_t>(level) + value) >
+          static_cast<uint32_t>(LogLevel::MAX_LEVEL))
+      ? LogLevel::MAX_LEVEL
+      : static_cast<LogLevel>(static_cast<uint32_t>(level) + value);
 }
 inline LogLevel& operator+=(LogLevel& level, uint32_t value) {
   level = level + value;