Make some static class members constexpr

This allows them to be ODR used in C++17 mode. NFC.
This commit is contained in:
Benjamin Kramer 2020-04-22 12:09:37 +02:00
parent 2bf5674317
commit b198f1f86c
14 changed files with 38 additions and 38 deletions

View 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;

View 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

View 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

View 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;

View 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 *;

View 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.

View 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>>;

View 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>>;

View 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:

View 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

View 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

View 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())

View 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

View File

@ -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