[llvm] a365f29 - [Support] Use a custom base class for FormatVariadicTest.cpp (NFC)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 21 12:22:22 PST 2022
Author: Kazu Hirata
Date: 2022-11-21T12:22:16-08:00
New Revision: a365f293dcab9d408b630a525cd6cab0d48df84f
URL: https://github.com/llvm/llvm-project/commit/a365f293dcab9d408b630a525cd6cab0d48df84f
DIFF: https://github.com/llvm/llvm-project/commit/a365f293dcab9d408b630a525cd6cab0d48df84f.diff
LOG: [Support] Use a custom base class for FormatVariadicTest.cpp (NFC)
This patch replaces None with a custom base class in
FormatVariadicTest.cpp.
As part of the migration from llvm::Optional to std::optional, I'd
like to define None as std::nullopt, but FormatVariadicTest.cpp blocks
that.
When you specialize indexed_accessor_range with the base class being
None, the template instantiation eventually generates code to compare
two instances of None. That's not guaranteed with std::nullopt.
Replacing None with a custom base class allows me to define None as
std::nullopt.
This is part of an effort to migrate from llvm::Optional to
std::optional:
https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
Differential Revision: https://reviews.llvm.org/D138381
Added:
Modified:
llvm/unittests/Support/FormatVariadicTest.cpp
Removed:
################################################################################
diff --git a/llvm/unittests/Support/FormatVariadicTest.cpp b/llvm/unittests/Support/FormatVariadicTest.cpp
index 44e4477eb0b08..58c89aad7a85b 100644
--- a/llvm/unittests/Support/FormatVariadicTest.cpp
+++ b/llvm/unittests/Support/FormatVariadicTest.cpp
@@ -706,20 +706,21 @@ TEST(FormatVariadicTest, FormatFilterRange) {
namespace {
+enum class Base { First };
+
class IntegerValuesRange final
- : public indexed_accessor_range<IntegerValuesRange, NoneType, int, int *,
- int> {
+ : public indexed_accessor_range<IntegerValuesRange, Base, int, int *, int> {
public:
- using indexed_accessor_range<IntegerValuesRange, NoneType, int, int *,
+ using indexed_accessor_range<IntegerValuesRange, Base, int, int *,
int>::indexed_accessor_range;
- static int dereference(const NoneType &, ptr
diff _t Index) {
+ static int dereference(const Base &, ptr
diff _t Index) {
return static_cast<int>(Index);
}
};
TEST(FormatVariadicTest, FormatRangeNonRef) {
- IntegerValuesRange Range(None, 0, 3);
+ IntegerValuesRange Range(Base(), 0, 3);
EXPECT_EQ("0, 1, 2",
formatv("{0}", make_range(Range.begin(), Range.end())).str());
}
More information about the llvm-commits
mailing list