-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[llvm] Use std::bool_constant (NFC) #158520
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[llvm] Use std::bool_constant (NFC) #158520
Conversation
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.
@llvm/pr-subscribers-llvm-ir @llvm/pr-subscribers-llvm-support Author: Kazu Hirata (kazutakahirata) ChangesThis patch replaces, std::integral_constant<bool, ...> with There are cases where we could replace EXPECT_EQ(false, ...) with Full diff: https://github.com/llvm/llvm-project/pull/158520.diff 3 Files Affected:
diff --git a/llvm/include/llvm/Support/YAMLTraits.h b/llvm/include/llvm/Support/YAMLTraits.h
index cce36a253777b..bbc12a2fcbe7a 100644
--- a/llvm/include/llvm/Support/YAMLTraits.h
+++ b/llvm/include/llvm/Support/YAMLTraits.h
@@ -668,17 +668,15 @@ inline QuotingType needsQuotes(StringRef S, bool ForcePreserveAsString = true) {
template <typename T, typename Context>
struct missingTraits
- : public std::integral_constant<bool,
- !has_ScalarEnumerationTraits<T>::value &&
- !has_ScalarBitSetTraits<T>::value &&
- !has_ScalarTraits<T>::value &&
- !has_BlockScalarTraits<T>::value &&
- !has_TaggedScalarTraits<T>::value &&
- !has_MappingTraits<T, Context>::value &&
- !has_SequenceTraits<T>::value &&
- !has_CustomMappingTraits<T>::value &&
- !has_DocumentListTraits<T>::value &&
- !has_PolymorphicTraits<T>::value> {};
+ : public std::bool_constant<
+ !has_ScalarEnumerationTraits<T>::value &&
+ !has_ScalarBitSetTraits<T>::value && !has_ScalarTraits<T>::value &&
+ !has_BlockScalarTraits<T>::value &&
+ !has_TaggedScalarTraits<T>::value &&
+ !has_MappingTraits<T, Context>::value &&
+ !has_SequenceTraits<T>::value && !has_CustomMappingTraits<T>::value &&
+ !has_DocumentListTraits<T>::value &&
+ !has_PolymorphicTraits<T>::value> {};
template <typename T, typename Context>
struct validatedMappingTraits
diff --git a/llvm/lib/IR/Metadata.cpp b/llvm/lib/IR/Metadata.cpp
index 1157cbe6bbc1b..fc78a5b299f49 100644
--- a/llvm/lib/IR/Metadata.cpp
+++ b/llvm/lib/IR/Metadata.cpp
@@ -1007,8 +1007,7 @@ MDNode *MDNode::uniquify() {
#define HANDLE_MDNODE_LEAF_UNIQUABLE(CLASS) \
case CLASS##Kind: { \
CLASS *SubclassThis = cast<CLASS>(this); \
- std::integral_constant<bool, HasCachedHash<CLASS>::value> \
- ShouldRecalculateHash; \
+ std::bool_constant<HasCachedHash<CLASS>::value> ShouldRecalculateHash; \
dispatchRecalculateHash(SubclassThis, ShouldRecalculateHash); \
return uniquifyImpl(SubclassThis, getContext().pImpl->CLASS##s); \
}
@@ -1065,7 +1064,7 @@ void MDNode::storeDistinctInContext() {
llvm_unreachable("Invalid subclass of MDNode");
#define HANDLE_MDNODE_LEAF(CLASS) \
case CLASS##Kind: { \
- std::integral_constant<bool, HasCachedHash<CLASS>::value> ShouldResetHash; \
+ std::bool_constant<HasCachedHash<CLASS>::value> ShouldResetHash; \
dispatchResetHash(cast<CLASS>(this), ShouldResetHash); \
break; \
}
diff --git a/llvm/unittests/ADT/StringRefTest.cpp b/llvm/unittests/ADT/StringRefTest.cpp
index d5f8dc41cdb6b..1ace29e96dbb8 100644
--- a/llvm/unittests/ADT/StringRefTest.cpp
+++ b/llvm/unittests/ADT/StringRefTest.cpp
@@ -1124,14 +1124,13 @@ TEST(StringRefTest, StringLiteral) {
constexpr StringRef StringRefs[] = {"Foo", "Bar"};
EXPECT_EQ(StringRef("Foo"), StringRefs[0]);
EXPECT_EQ(3u, (std::integral_constant<size_t, StringRefs[0].size()>::value));
- EXPECT_EQ(false,
- (std::integral_constant<bool, StringRefs[0].empty()>::value));
+ EXPECT_EQ(false, (std::bool_constant<StringRefs[0].empty()>::value));
EXPECT_EQ(StringRef("Bar"), StringRefs[1]);
constexpr StringLiteral Strings[] = {"Foo", "Bar"};
EXPECT_EQ(StringRef("Foo"), Strings[0]);
EXPECT_EQ(3u, (std::integral_constant<size_t, Strings[0].size()>::value));
- EXPECT_EQ(false, (std::integral_constant<bool, Strings[0].empty()>::value));
+ EXPECT_EQ(false, (std::bool_constant<Strings[0].empty()>::value));
EXPECT_EQ(StringRef("Bar"), Strings[1]);
}
|
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.