[PATCH] D138381: [Support] Use a custom base class for FormatVariadicTest.cpp (NFC)
Kazu Hirata via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sun Nov 20 09:02:30 PST 2022
kazu created this revision.
Herald added a project: All.
kazu requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
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
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D138381
Files:
llvm/unittests/Support/FormatVariadicTest.cpp
Index: llvm/unittests/Support/FormatVariadicTest.cpp
===================================================================
--- llvm/unittests/Support/FormatVariadicTest.cpp
+++ llvm/unittests/Support/FormatVariadicTest.cpp
@@ -706,20 +706,21 @@
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 &, ptrdiff_t Index) {
+ static int dereference(const Base &, ptrdiff_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());
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D138381.476752.patch
Type: text/x-patch
Size: 1148 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221120/6e1907d0/attachment.bin>
More information about the llvm-commits
mailing list