Skip to content

Commit 0984b15

Browse files
authored
Merge pull request #30086 from CodaFi/constexpert-mode
[NFC] Mark The OptionSet API constexpr
2 parents 78b6759 + 581d007 commit 0984b15

File tree

1 file changed

+19
-18
lines changed

1 file changed

+19
-18
lines changed

include/swift/Basic/OptionSet.h

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -50,45 +50,46 @@ class OptionSet {
5050

5151
public:
5252
/// Create an empty option set.
53-
OptionSet() : Storage() { }
53+
constexpr OptionSet() : Storage() {}
5454

5555
/// Create an empty option set.
56-
OptionSet(llvm::NoneType) : Storage() { }
56+
constexpr OptionSet(llvm::NoneType) : Storage() {}
5757

5858
/// Create an option set with only the given option set.
59-
OptionSet(Flags flag) : Storage(static_cast<StorageType>(flag)) { }
59+
constexpr OptionSet(Flags flag) : Storage(static_cast<StorageType>(flag)) {}
6060

6161
/// Create an option set from raw storage.
62-
explicit OptionSet(StorageType storage) : Storage(storage) { }
62+
explicit constexpr OptionSet(StorageType storage) : Storage(storage) {}
6363

6464
/// Check whether an option set is non-empty.
65-
explicit operator bool() const { return Storage != 0; }
65+
explicit constexpr operator bool() const { return Storage != 0; }
6666

6767
/// Explicitly convert an option set to its underlying storage.
68-
explicit operator StorageType() const { return Storage; }
68+
explicit constexpr operator StorageType() const { return Storage; }
6969

7070
/// Explicitly convert an option set to intptr_t, for use in
7171
/// llvm::PointerIntPair.
7272
///
7373
/// This member is not present if the underlying type is bigger than
7474
/// a pointer.
7575
template <typename T = std::intptr_t>
76-
explicit operator typename std::enable_if<sizeof(StorageType) <= sizeof(T),
77-
std::intptr_t>::type () const {
76+
explicit constexpr
77+
operator typename std::enable_if<sizeof(StorageType) <= sizeof(T),
78+
std::intptr_t>::type() const {
7879
return static_cast<intptr_t>(Storage);
7980
}
8081

8182
/// Retrieve the "raw" representation of this option set.
8283
StorageType toRaw() const { return Storage; }
83-
84+
8485
/// Determine whether this option set contains all of the options in the
8586
/// given set.
86-
bool contains(OptionSet set) const {
87+
constexpr bool contains(OptionSet set) const {
8788
return !static_cast<bool>(set - *this);
8889
}
8990

9091
/// Check if this option set contains the exact same options as the given set.
91-
bool containsOnly(OptionSet set) const {
92+
constexpr bool containsOnly(OptionSet set) const {
9293
return Storage == set.Storage;
9394
}
9495

@@ -97,34 +98,34 @@ class OptionSet {
9798
// want '==' behavior, use 'containsOnly'.
9899

99100
/// Produce the union of two option sets.
100-
friend OptionSet operator|(OptionSet lhs, OptionSet rhs) {
101+
friend constexpr OptionSet operator|(OptionSet lhs, OptionSet rhs) {
101102
return OptionSet(lhs.Storage | rhs.Storage);
102103
}
103104

104105
/// Produce the union of two option sets.
105-
friend OptionSet &operator|=(OptionSet &lhs, OptionSet rhs) {
106+
friend constexpr OptionSet &operator|=(OptionSet &lhs, OptionSet rhs) {
106107
lhs.Storage |= rhs.Storage;
107108
return lhs;
108-
}
109+
}
109110

110111
/// Produce the intersection of two option sets.
111-
friend OptionSet operator&(OptionSet lhs, OptionSet rhs) {
112+
friend constexpr OptionSet operator&(OptionSet lhs, OptionSet rhs) {
112113
return OptionSet(lhs.Storage & rhs.Storage);
113114
}
114115

115116
/// Produce the intersection of two option sets.
116-
friend OptionSet &operator&=(OptionSet &lhs, OptionSet rhs) {
117+
friend constexpr OptionSet &operator&=(OptionSet &lhs, OptionSet rhs) {
117118
lhs.Storage &= rhs.Storage;
118119
return lhs;
119120
}
120121

121122
/// Produce the difference of two option sets.
122-
friend OptionSet operator-(OptionSet lhs, OptionSet rhs) {
123+
friend constexpr OptionSet operator-(OptionSet lhs, OptionSet rhs) {
123124
return OptionSet(lhs.Storage & ~rhs.Storage);
124125
}
125126

126127
/// Produce the difference of two option sets.
127-
friend OptionSet &operator-=(OptionSet &lhs, OptionSet rhs) {
128+
friend constexpr OptionSet &operator-=(OptionSet &lhs, OptionSet rhs) {
128129
lhs.Storage &= ~rhs.Storage;
129130
return lhs;
130131
}

0 commit comments

Comments
 (0)