OSDN Git Service

Make some static class members constexpr
authorBenjamin Kramer <benny.kra@googlemail.com>
Wed, 22 Apr 2020 10:09:37 +0000 (12:09 +0200)
committerBenjamin Kramer <benny.kra@googlemail.com>
Wed, 22 Apr 2020 10:25:01 +0000 (12:25 +0200)
This allows them to be ODR used in C++17 mode. NFC.

14 files changed:
llvm/include/llvm/ADT/APFloat.h
llvm/include/llvm/ADT/APInt.h
llvm/include/llvm/ADT/Hashing.h
llvm/include/llvm/ADT/SparseMultiSet.h
llvm/include/llvm/ADT/StringRef.h
llvm/include/llvm/Support/BranchProbability.h
llvm/include/llvm/Support/Error.h
llvm/include/llvm/Support/ErrorOr.h
llvm/include/llvm/Support/ScaledNumber.h
llvm/include/llvm/Support/circular_raw_ostream.h
llvm/include/llvm/Support/raw_ostream.h
llvm/lib/Support/BranchProbability.cpp
llvm/lib/Support/StringRef.cpp
llvm/lib/Support/raw_ostream.cpp

index 37aa6dc..1c17f10 100644 (file)
@@ -142,7 +142,7 @@ enum lostFraction { // Example of truncated bits:
 // members.
 struct APFloatBase {
   typedef APInt::WordType integerPart;
-  static const unsigned integerPartWidth = APInt::APINT_BITS_PER_WORD;
+  static constexpr unsigned integerPartWidth = APInt::APINT_BITS_PER_WORD;
 
   /// A signed type to represent a floating point numbers unbiased exponent.
   typedef int32_t ExponentType;
index 0791a6d..9f0fb04 100644 (file)
@@ -84,7 +84,7 @@ public:
     UP,
   };
 
-  static const WordType WORDTYPE_MAX = ~WordType(0);
+  static constexpr WordType WORDTYPE_MAX = ~WordType(0);
 
 private:
   /// This union is used to store the integer value. When the
index dac0e05..9ee310c 100644 (file)
@@ -157,10 +157,10 @@ inline uint32_t fetch32(const char *p) {
 }
 
 /// Some primes between 2^63 and 2^64 for various uses.
-static const uint64_t k0 = 0xc3a5c85c97cb3127ULL;
-static const uint64_t k1 = 0xb492b66fbe98f273ULL;
-static const uint64_t k2 = 0x9ae16a3b2f90404fULL;
-static const uint64_t k3 = 0xc949d7c7509e6557ULL;
+static constexpr uint64_t k0 = 0xc3a5c85c97cb3127ULL;
+static constexpr uint64_t k1 = 0xb492b66fbe98f273ULL;
+static constexpr uint64_t k2 = 0x9ae16a3b2f90404fULL;
+static constexpr uint64_t k3 = 0xc949d7c7509e6557ULL;
 
 /// Bitwise right rotate.
 /// Normally this will compile to a single instruction, especially if the
index d9d3ff4..307d2c3 100644 (file)
@@ -94,7 +94,7 @@ class SparseMultiSet {
   /// tombstones, in which case they are actually nodes in a single-linked
   /// freelist of recyclable slots.
   struct SMSNode {
-    static const unsigned INVALID = ~0U;
+    static constexpr unsigned INVALID = ~0U;
 
     ValueT Data;
     unsigned Prev;
index add5d37..98c120f 100644 (file)
@@ -56,7 +56,7 @@ namespace llvm {
   /// general safe to store a StringRef.
   class LLVM_GSL_POINTER StringRef {
   public:
-    static const size_t npos = ~size_t(0);
+    static constexpr size_t npos = ~size_t(0);
 
     using iterator = const char *;
     using const_iterator = const char *;
index cd9d369..6c7ad1f 100644 (file)
@@ -32,8 +32,8 @@ class BranchProbability {
   uint32_t N;
 
   // Denominator, which is a constant value.
-  static const uint32_t D = 1u << 31;
-  static const uint32_t UnknownN = UINT32_MAX;
+  static constexpr uint32_t D = 1u << 31;
+  static constexpr uint32_t UnknownN = UINT32_MAX;
 
   // Construct a BranchProbability with only numerator assuming the denominator
   // is 1<<31. For internal use only.
index b29a247..9dd1bb7 100644 (file)
@@ -440,7 +440,7 @@ template <class T> class LLVM_NODISCARD Expected {
   template <class T1> friend class ExpectedAsOutParameter;
   template <class OtherT> friend class Expected;
 
-  static const bool isRef = std::is_reference<T>::value;
+  static constexpr bool isRef = std::is_reference<T>::value;
 
   using wrap = std::reference_wrapper<std::remove_reference_t<T>>;
 
index 4750cd8..1fbccc1 100644 (file)
@@ -56,7 +56,7 @@ template<class T>
 class ErrorOr {
   template <class OtherT> friend class ErrorOr;
 
-  static const bool isRef = std::is_reference<T>::value;
+  static constexpr bool isRef = std::is_reference<T>::value;
 
   using wrap = std::reference_wrapper<std::remove_reference_t<T>>;
 
index 552da34..a5261e4 100644 (file)
@@ -418,7 +418,7 @@ namespace llvm {
 class raw_ostream;
 class ScaledNumberBase {
 public:
-  static const int DefaultPrecision = 10;
+  static constexpr int DefaultPrecision = 10;
 
   static void dump(uint64_t D, int16_t E, int Width);
   static raw_ostream &print(raw_ostream &OS, uint64_t D, int16_t E, int Width,
@@ -499,7 +499,7 @@ public:
 private:
   typedef std::numeric_limits<DigitsType> DigitsLimits;
 
-  static const int Width = sizeof(DigitsType) * 8;
+  static constexpr int Width = sizeof(DigitsType) * 8;
   static_assert(Width <= 64, "invalid integer width for digits");
 
 private:
index a72acd4..d2f01ea 100644 (file)
@@ -27,12 +27,12 @@ namespace llvm {
     /// stream and is responsible for cleanup, memory management
     /// issues, etc.
     ///
-    static const bool TAKE_OWNERSHIP = true;
+    static constexpr bool TAKE_OWNERSHIP = true;
 
     /// REFERENCE_ONLY - Tell this stream it should not manage the
     /// held stream.
     ///
-    static const bool REFERENCE_ONLY = false;
+    static constexpr bool REFERENCE_ONLY = false;
 
   private:
     /// TheStream - The real stream we output to. We set it to be
index 30a1e62..f7223dc 100644 (file)
@@ -86,16 +86,16 @@ public:
     RESET,
   };
 
-  static const Colors BLACK = Colors::BLACK;
-  static const Colors RED = Colors::RED;
-  static const Colors GREEN = Colors::GREEN;
-  static const Colors YELLOW = Colors::YELLOW;
-  static const Colors BLUE = Colors::BLUE;
-  static const Colors MAGENTA = Colors::MAGENTA;
-  static const Colors CYAN = Colors::CYAN;
-  static const Colors WHITE = Colors::WHITE;
-  static const Colors SAVEDCOLOR = Colors::SAVEDCOLOR;
-  static const Colors RESET = Colors::RESET;
+  static constexpr Colors BLACK = Colors::BLACK;
+  static constexpr Colors RED = Colors::RED;
+  static constexpr Colors GREEN = Colors::GREEN;
+  static constexpr Colors YELLOW = Colors::YELLOW;
+  static constexpr Colors BLUE = Colors::BLUE;
+  static constexpr Colors MAGENTA = Colors::MAGENTA;
+  static constexpr Colors CYAN = Colors::CYAN;
+  static constexpr Colors WHITE = Colors::WHITE;
+  static constexpr Colors SAVEDCOLOR = Colors::SAVEDCOLOR;
+  static constexpr Colors RESET = Colors::RESET;
 
   explicit raw_ostream(bool unbuffered = false)
       : BufferMode(unbuffered ? BufferKind::Unbuffered
index 195e2d5..60d5478 100644 (file)
@@ -19,7 +19,7 @@
 
 using namespace llvm;
 
-const uint32_t BranchProbability::D;
+constexpr uint32_t BranchProbability::D;
 
 raw_ostream &BranchProbability::print(raw_ostream &OS) const {
   if (isUnknown())
index 104482d..6ae2a2b 100644 (file)
@@ -19,7 +19,7 @@ using namespace llvm;
 
 // MSVC emits references to this into the translation units which reference it.
 #ifndef _MSC_VER
-const size_t StringRef::npos;
+constexpr size_t StringRef::npos;
 #endif
 
 // strncasecmp() is not available on non-POSIX systems, so define an
index 7e9428e..fa69fe3 100644 (file)
 
 using namespace llvm;
 
-const raw_ostream::Colors raw_ostream::BLACK;
-const raw_ostream::Colors raw_ostream::RED;
-const raw_ostream::Colors raw_ostream::GREEN;
-const raw_ostream::Colors raw_ostream::YELLOW;
-const raw_ostream::Colors raw_ostream::BLUE;
-const raw_ostream::Colors raw_ostream::MAGENTA;
-const raw_ostream::Colors raw_ostream::CYAN;
-const raw_ostream::Colors raw_ostream::WHITE;
-const raw_ostream::Colors raw_ostream::SAVEDCOLOR;
-const raw_ostream::Colors raw_ostream::RESET;
+constexpr raw_ostream::Colors raw_ostream::BLACK;
+constexpr raw_ostream::Colors raw_ostream::RED;
+constexpr raw_ostream::Colors raw_ostream::GREEN;
+constexpr raw_ostream::Colors raw_ostream::YELLOW;
+constexpr raw_ostream::Colors raw_ostream::BLUE;
+constexpr raw_ostream::Colors raw_ostream::MAGENTA;
+constexpr raw_ostream::Colors raw_ostream::CYAN;
+constexpr raw_ostream::Colors raw_ostream::WHITE;
+constexpr raw_ostream::Colors raw_ostream::SAVEDCOLOR;
+constexpr raw_ostream::Colors raw_ostream::RESET;
 
 raw_ostream::~raw_ostream() {
   // raw_ostream's subclasses should take care to flush the buffer