[llvm] b198f1f - Make some static class members constexpr
Benjamin Kramer via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 22 03:26:09 PDT 2020
Author: Benjamin Kramer
Date: 2020-04-22T12:25:01+02:00
New Revision: b198f1f86ce09b86825dd6d80de2c72a617e27f7
URL: https://github.com/llvm/llvm-project/commit/b198f1f86ce09b86825dd6d80de2c72a617e27f7
DIFF: https://github.com/llvm/llvm-project/commit/b198f1f86ce09b86825dd6d80de2c72a617e27f7.diff
LOG: Make some static class members constexpr
This allows them to be ODR used in C++17 mode. NFC.
Added:
Modified:
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
Removed:
################################################################################
diff --git a/llvm/include/llvm/ADT/APFloat.h b/llvm/include/llvm/ADT/APFloat.h
index 37aa6dce7f11..1c17f10691e7 100644
--- a/llvm/include/llvm/ADT/APFloat.h
+++ b/llvm/include/llvm/ADT/APFloat.h
@@ -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;
diff --git a/llvm/include/llvm/ADT/APInt.h b/llvm/include/llvm/ADT/APInt.h
index 0791a6d686a3..9f0fb04794ea 100644
--- a/llvm/include/llvm/ADT/APInt.h
+++ b/llvm/include/llvm/ADT/APInt.h
@@ -84,7 +84,7 @@ class LLVM_NODISCARD APInt {
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
diff --git a/llvm/include/llvm/ADT/Hashing.h b/llvm/include/llvm/ADT/Hashing.h
index dac0e0556ff3..9ee310c879fd 100644
--- a/llvm/include/llvm/ADT/Hashing.h
+++ b/llvm/include/llvm/ADT/Hashing.h
@@ -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
diff --git a/llvm/include/llvm/ADT/SparseMultiSet.h b/llvm/include/llvm/ADT/SparseMultiSet.h
index d9d3ff459267..307d2c3f84e5 100644
--- a/llvm/include/llvm/ADT/SparseMultiSet.h
+++ b/llvm/include/llvm/ADT/SparseMultiSet.h
@@ -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;
diff --git a/llvm/include/llvm/ADT/StringRef.h b/llvm/include/llvm/ADT/StringRef.h
index add5d37f89f7..98c120fe2d2e 100644
--- a/llvm/include/llvm/ADT/StringRef.h
+++ b/llvm/include/llvm/ADT/StringRef.h
@@ -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 *;
diff --git a/llvm/include/llvm/Support/BranchProbability.h b/llvm/include/llvm/Support/BranchProbability.h
index cd9d369b4f4e..6c7ad1fe2a52 100644
--- a/llvm/include/llvm/Support/BranchProbability.h
+++ b/llvm/include/llvm/Support/BranchProbability.h
@@ -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.
diff --git a/llvm/include/llvm/Support/Error.h b/llvm/include/llvm/Support/Error.h
index b29a247ff8ce..9dd1bb7cb96d 100644
--- a/llvm/include/llvm/Support/Error.h
+++ b/llvm/include/llvm/Support/Error.h
@@ -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>>;
diff --git a/llvm/include/llvm/Support/ErrorOr.h b/llvm/include/llvm/Support/ErrorOr.h
index 4750cd832ef7..1fbccc1d1e26 100644
--- a/llvm/include/llvm/Support/ErrorOr.h
+++ b/llvm/include/llvm/Support/ErrorOr.h
@@ -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>>;
diff --git a/llvm/include/llvm/Support/ScaledNumber.h b/llvm/include/llvm/Support/ScaledNumber.h
index 552da34f357b..a5261e419986 100644
--- a/llvm/include/llvm/Support/ScaledNumber.h
+++ b/llvm/include/llvm/Support/ScaledNumber.h
@@ -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 @@ template <class DigitsT> class ScaledNumber : ScaledNumberBase {
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:
diff --git a/llvm/include/llvm/Support/circular_raw_ostream.h b/llvm/include/llvm/Support/circular_raw_ostream.h
index a72acd4fe002..d2f01ea6a7f2 100644
--- a/llvm/include/llvm/Support/circular_raw_ostream.h
+++ b/llvm/include/llvm/Support/circular_raw_ostream.h
@@ -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
diff --git a/llvm/include/llvm/Support/raw_ostream.h b/llvm/include/llvm/Support/raw_ostream.h
index 30a1e62330df..f7223dc8c8cf 100644
--- a/llvm/include/llvm/Support/raw_ostream.h
+++ b/llvm/include/llvm/Support/raw_ostream.h
@@ -86,16 +86,16 @@ class raw_ostream {
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
diff --git a/llvm/lib/Support/BranchProbability.cpp b/llvm/lib/Support/BranchProbability.cpp
index 195e2d58d8e1..60d5478a9052 100644
--- a/llvm/lib/Support/BranchProbability.cpp
+++ b/llvm/lib/Support/BranchProbability.cpp
@@ -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())
diff --git a/llvm/lib/Support/StringRef.cpp b/llvm/lib/Support/StringRef.cpp
index 104482de4ad7..6ae2a2b532aa 100644
--- a/llvm/lib/Support/StringRef.cpp
+++ b/llvm/lib/Support/StringRef.cpp
@@ -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
diff --git a/llvm/lib/Support/raw_ostream.cpp b/llvm/lib/Support/raw_ostream.cpp
index 7e9428e5dbc9..fa69fe3c7154 100644
--- a/llvm/lib/Support/raw_ostream.cpp
+++ b/llvm/lib/Support/raw_ostream.cpp
@@ -65,16 +65,16 @@
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
More information about the llvm-commits
mailing list