Skip to content

Commit 1e3dd5e

Browse files
[llvm] Use std::bool_constant (NFC) (#158520)
This patch replaces, std::integral_constant<bool, ...> with std::bool_constant for brevity. Note that std::bool_constant was introduced as part of C++17. There are cases where we could replace EXPECT_EQ(false, ...) with EXPECT_FALSE(...), but I'm not doing that in this patch to avoid doing multiple things in one patch.
1 parent b157193 commit 1e3dd5e

File tree

3 files changed

+13
-17
lines changed

3 files changed

+13
-17
lines changed

llvm/include/llvm/Support/YAMLTraits.h

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -668,17 +668,15 @@ inline QuotingType needsQuotes(StringRef S, bool ForcePreserveAsString = true) {
668668

669669
template <typename T, typename Context>
670670
struct missingTraits
671-
: public std::integral_constant<bool,
672-
!has_ScalarEnumerationTraits<T>::value &&
673-
!has_ScalarBitSetTraits<T>::value &&
674-
!has_ScalarTraits<T>::value &&
675-
!has_BlockScalarTraits<T>::value &&
676-
!has_TaggedScalarTraits<T>::value &&
677-
!has_MappingTraits<T, Context>::value &&
678-
!has_SequenceTraits<T>::value &&
679-
!has_CustomMappingTraits<T>::value &&
680-
!has_DocumentListTraits<T>::value &&
681-
!has_PolymorphicTraits<T>::value> {};
671+
: public std::bool_constant<
672+
!has_ScalarEnumerationTraits<T>::value &&
673+
!has_ScalarBitSetTraits<T>::value && !has_ScalarTraits<T>::value &&
674+
!has_BlockScalarTraits<T>::value &&
675+
!has_TaggedScalarTraits<T>::value &&
676+
!has_MappingTraits<T, Context>::value &&
677+
!has_SequenceTraits<T>::value && !has_CustomMappingTraits<T>::value &&
678+
!has_DocumentListTraits<T>::value &&
679+
!has_PolymorphicTraits<T>::value> {};
682680

683681
template <typename T, typename Context>
684682
struct validatedMappingTraits

llvm/lib/IR/Metadata.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,8 +1007,7 @@ MDNode *MDNode::uniquify() {
10071007
#define HANDLE_MDNODE_LEAF_UNIQUABLE(CLASS) \
10081008
case CLASS##Kind: { \
10091009
CLASS *SubclassThis = cast<CLASS>(this); \
1010-
std::integral_constant<bool, HasCachedHash<CLASS>::value> \
1011-
ShouldRecalculateHash; \
1010+
std::bool_constant<HasCachedHash<CLASS>::value> ShouldRecalculateHash; \
10121011
dispatchRecalculateHash(SubclassThis, ShouldRecalculateHash); \
10131012
return uniquifyImpl(SubclassThis, getContext().pImpl->CLASS##s); \
10141013
}
@@ -1065,7 +1064,7 @@ void MDNode::storeDistinctInContext() {
10651064
llvm_unreachable("Invalid subclass of MDNode");
10661065
#define HANDLE_MDNODE_LEAF(CLASS) \
10671066
case CLASS##Kind: { \
1068-
std::integral_constant<bool, HasCachedHash<CLASS>::value> ShouldResetHash; \
1067+
std::bool_constant<HasCachedHash<CLASS>::value> ShouldResetHash; \
10691068
dispatchResetHash(cast<CLASS>(this), ShouldResetHash); \
10701069
break; \
10711070
}

llvm/unittests/ADT/StringRefTest.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1124,14 +1124,13 @@ TEST(StringRefTest, StringLiteral) {
11241124
constexpr StringRef StringRefs[] = {"Foo", "Bar"};
11251125
EXPECT_EQ(StringRef("Foo"), StringRefs[0]);
11261126
EXPECT_EQ(3u, (std::integral_constant<size_t, StringRefs[0].size()>::value));
1127-
EXPECT_EQ(false,
1128-
(std::integral_constant<bool, StringRefs[0].empty()>::value));
1127+
EXPECT_EQ(false, (std::bool_constant<StringRefs[0].empty()>::value));
11291128
EXPECT_EQ(StringRef("Bar"), StringRefs[1]);
11301129

11311130
constexpr StringLiteral Strings[] = {"Foo", "Bar"};
11321131
EXPECT_EQ(StringRef("Foo"), Strings[0]);
11331132
EXPECT_EQ(3u, (std::integral_constant<size_t, Strings[0].size()>::value));
1134-
EXPECT_EQ(false, (std::integral_constant<bool, Strings[0].empty()>::value));
1133+
EXPECT_EQ(false, (std::bool_constant<Strings[0].empty()>::value));
11351134
EXPECT_EQ(StringRef("Bar"), Strings[1]);
11361135
}
11371136

0 commit comments

Comments
 (0)