Skip to content

Commit b198f1f

Browse files
committed
Make some static class members constexpr
This allows them to be ODR used in C++17 mode. NFC.
1 parent 2bf5674 commit b198f1f

14 files changed

+38
-38
lines changed

llvm/include/llvm/ADT/APFloat.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ enum lostFraction { // Example of truncated bits:
142142
// members.
143143
struct APFloatBase {
144144
typedef APInt::WordType integerPart;
145-
static const unsigned integerPartWidth = APInt::APINT_BITS_PER_WORD;
145+
static constexpr unsigned integerPartWidth = APInt::APINT_BITS_PER_WORD;
146146

147147
/// A signed type to represent a floating point numbers unbiased exponent.
148148
typedef int32_t ExponentType;

llvm/include/llvm/ADT/APInt.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class LLVM_NODISCARD APInt {
8484
UP,
8585
};
8686

87-
static const WordType WORDTYPE_MAX = ~WordType(0);
87+
static constexpr WordType WORDTYPE_MAX = ~WordType(0);
8888

8989
private:
9090
/// This union is used to store the integer value. When the

llvm/include/llvm/ADT/Hashing.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,10 @@ inline uint32_t fetch32(const char *p) {
157157
}
158158

159159
/// Some primes between 2^63 and 2^64 for various uses.
160-
static const uint64_t k0 = 0xc3a5c85c97cb3127ULL;
161-
static const uint64_t k1 = 0xb492b66fbe98f273ULL;
162-
static const uint64_t k2 = 0x9ae16a3b2f90404fULL;
163-
static const uint64_t k3 = 0xc949d7c7509e6557ULL;
160+
static constexpr uint64_t k0 = 0xc3a5c85c97cb3127ULL;
161+
static constexpr uint64_t k1 = 0xb492b66fbe98f273ULL;
162+
static constexpr uint64_t k2 = 0x9ae16a3b2f90404fULL;
163+
static constexpr uint64_t k3 = 0xc949d7c7509e6557ULL;
164164

165165
/// Bitwise right rotate.
166166
/// Normally this will compile to a single instruction, especially if the

llvm/include/llvm/ADT/SparseMultiSet.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ class SparseMultiSet {
9494
/// tombstones, in which case they are actually nodes in a single-linked
9595
/// freelist of recyclable slots.
9696
struct SMSNode {
97-
static const unsigned INVALID = ~0U;
97+
static constexpr unsigned INVALID = ~0U;
9898

9999
ValueT Data;
100100
unsigned Prev;

llvm/include/llvm/ADT/StringRef.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ namespace llvm {
5656
/// general safe to store a StringRef.
5757
class LLVM_GSL_POINTER StringRef {
5858
public:
59-
static const size_t npos = ~size_t(0);
59+
static constexpr size_t npos = ~size_t(0);
6060

6161
using iterator = const char *;
6262
using const_iterator = const char *;

llvm/include/llvm/Support/BranchProbability.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ class BranchProbability {
3232
uint32_t N;
3333

3434
// Denominator, which is a constant value.
35-
static const uint32_t D = 1u << 31;
36-
static const uint32_t UnknownN = UINT32_MAX;
35+
static constexpr uint32_t D = 1u << 31;
36+
static constexpr uint32_t UnknownN = UINT32_MAX;
3737

3838
// Construct a BranchProbability with only numerator assuming the denominator
3939
// is 1<<31. For internal use only.

llvm/include/llvm/Support/Error.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ template <class T> class LLVM_NODISCARD Expected {
440440
template <class T1> friend class ExpectedAsOutParameter;
441441
template <class OtherT> friend class Expected;
442442

443-
static const bool isRef = std::is_reference<T>::value;
443+
static constexpr bool isRef = std::is_reference<T>::value;
444444

445445
using wrap = std::reference_wrapper<std::remove_reference_t<T>>;
446446

llvm/include/llvm/Support/ErrorOr.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ template<class T>
5656
class ErrorOr {
5757
template <class OtherT> friend class ErrorOr;
5858

59-
static const bool isRef = std::is_reference<T>::value;
59+
static constexpr bool isRef = std::is_reference<T>::value;
6060

6161
using wrap = std::reference_wrapper<std::remove_reference_t<T>>;
6262

llvm/include/llvm/Support/ScaledNumber.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ namespace llvm {
418418
class raw_ostream;
419419
class ScaledNumberBase {
420420
public:
421-
static const int DefaultPrecision = 10;
421+
static constexpr int DefaultPrecision = 10;
422422

423423
static void dump(uint64_t D, int16_t E, int Width);
424424
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 {
499499
private:
500500
typedef std::numeric_limits<DigitsType> DigitsLimits;
501501

502-
static const int Width = sizeof(DigitsType) * 8;
502+
static constexpr int Width = sizeof(DigitsType) * 8;
503503
static_assert(Width <= 64, "invalid integer width for digits");
504504

505505
private:

llvm/include/llvm/Support/circular_raw_ostream.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ namespace llvm {
2727
/// stream and is responsible for cleanup, memory management
2828
/// issues, etc.
2929
///
30-
static const bool TAKE_OWNERSHIP = true;
30+
static constexpr bool TAKE_OWNERSHIP = true;
3131

3232
/// REFERENCE_ONLY - Tell this stream it should not manage the
3333
/// held stream.
3434
///
35-
static const bool REFERENCE_ONLY = false;
35+
static constexpr bool REFERENCE_ONLY = false;
3636

3737
private:
3838
/// TheStream - The real stream we output to. We set it to be

llvm/include/llvm/Support/raw_ostream.h

+10-10
Original file line numberDiff line numberDiff line change
@@ -86,16 +86,16 @@ class raw_ostream {
8686
RESET,
8787
};
8888

89-
static const Colors BLACK = Colors::BLACK;
90-
static const Colors RED = Colors::RED;
91-
static const Colors GREEN = Colors::GREEN;
92-
static const Colors YELLOW = Colors::YELLOW;
93-
static const Colors BLUE = Colors::BLUE;
94-
static const Colors MAGENTA = Colors::MAGENTA;
95-
static const Colors CYAN = Colors::CYAN;
96-
static const Colors WHITE = Colors::WHITE;
97-
static const Colors SAVEDCOLOR = Colors::SAVEDCOLOR;
98-
static const Colors RESET = Colors::RESET;
89+
static constexpr Colors BLACK = Colors::BLACK;
90+
static constexpr Colors RED = Colors::RED;
91+
static constexpr Colors GREEN = Colors::GREEN;
92+
static constexpr Colors YELLOW = Colors::YELLOW;
93+
static constexpr Colors BLUE = Colors::BLUE;
94+
static constexpr Colors MAGENTA = Colors::MAGENTA;
95+
static constexpr Colors CYAN = Colors::CYAN;
96+
static constexpr Colors WHITE = Colors::WHITE;
97+
static constexpr Colors SAVEDCOLOR = Colors::SAVEDCOLOR;
98+
static constexpr Colors RESET = Colors::RESET;
9999

100100
explicit raw_ostream(bool unbuffered = false)
101101
: BufferMode(unbuffered ? BufferKind::Unbuffered

llvm/lib/Support/BranchProbability.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
using namespace llvm;
2121

22-
const uint32_t BranchProbability::D;
22+
constexpr uint32_t BranchProbability::D;
2323

2424
raw_ostream &BranchProbability::print(raw_ostream &OS) const {
2525
if (isUnknown())

llvm/lib/Support/StringRef.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ using namespace llvm;
1919

2020
// MSVC emits references to this into the translation units which reference it.
2121
#ifndef _MSC_VER
22-
const size_t StringRef::npos;
22+
constexpr size_t StringRef::npos;
2323
#endif
2424

2525
// strncasecmp() is not available on non-POSIX systems, so define an

llvm/lib/Support/raw_ostream.cpp

+10-10
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,16 @@
6565

6666
using namespace llvm;
6767

68-
const raw_ostream::Colors raw_ostream::BLACK;
69-
const raw_ostream::Colors raw_ostream::RED;
70-
const raw_ostream::Colors raw_ostream::GREEN;
71-
const raw_ostream::Colors raw_ostream::YELLOW;
72-
const raw_ostream::Colors raw_ostream::BLUE;
73-
const raw_ostream::Colors raw_ostream::MAGENTA;
74-
const raw_ostream::Colors raw_ostream::CYAN;
75-
const raw_ostream::Colors raw_ostream::WHITE;
76-
const raw_ostream::Colors raw_ostream::SAVEDCOLOR;
77-
const raw_ostream::Colors raw_ostream::RESET;
68+
constexpr raw_ostream::Colors raw_ostream::BLACK;
69+
constexpr raw_ostream::Colors raw_ostream::RED;
70+
constexpr raw_ostream::Colors raw_ostream::GREEN;
71+
constexpr raw_ostream::Colors raw_ostream::YELLOW;
72+
constexpr raw_ostream::Colors raw_ostream::BLUE;
73+
constexpr raw_ostream::Colors raw_ostream::MAGENTA;
74+
constexpr raw_ostream::Colors raw_ostream::CYAN;
75+
constexpr raw_ostream::Colors raw_ostream::WHITE;
76+
constexpr raw_ostream::Colors raw_ostream::SAVEDCOLOR;
77+
constexpr raw_ostream::Colors raw_ostream::RESET;
7878

7979
raw_ostream::~raw_ostream() {
8080
// raw_ostream's subclasses should take care to flush the buffer

0 commit comments

Comments
 (0)