logging: add an assert for the FLAG_INHERIT bit
authorAdam Simpkins <simpkins@fb.com>
Thu, 30 Nov 2017 01:35:19 +0000 (17:35 -0800)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Thu, 30 Nov 2017 01:51:07 +0000 (17:51 -0800)
Summary:
Add a static_assert() to check that the FLAG_INHERIT bit does not conflict with
valid LogLevel values.

Reviewed By: bolinfest

Differential Revision: D6341242

fbshipit-source-id: cec284623c8a612a3c54f1b593d169310790616e

folly/experimental/logging/LogCategory.h

index e861252..5a67d9f 100644 (file)
@@ -221,6 +221,12 @@ class LogCategory {
  private:
   enum : uint32_t { FLAG_INHERIT = 0x80000000 };
 
+  // FLAG_INHERIT is the stored in the uppermost bit of the LogLevel field.
+  // assert that it does not conflict with valid LogLevel values.
+  static_assert(
+      static_cast<uint32_t>(LogLevel::MAX_LEVEL) < FLAG_INHERIT,
+      "The FLAG_INHERIT bit must not be set in any valid LogLevel value");
+
   // Forbidden copy constructor and assignment operator
   LogCategory(LogCategory const&) = delete;
   LogCategory& operator=(LogCategory const&) = delete;