This patch adds a formatter for std::ranges::ref_view<T>.
It simply holds a T*, so all this formatter does is dereference
this pointer and format it as T would be.
Testing
- Added API tests
Paths
| Differential D138558
[lldb][DataFormatter] Add std::ranges::ref_view formatter ClosedPublic Authored by Michael137 on Nov 23 2022, 3:11 AM.
Details Summary This patch adds a formatter for std::ranges::ref_view<T>. Testing
Diff Detail
Event TimelineComment Actions Small nitpicks, otherwise good!
This revision is now accepted and ready to land.Nov 29 2022, 1:50 PM Michael137 added inline comments. Closed by commit rG77b220524541: [lldb][DataFormatter] Add std::ranges::ref_view formatter (authored by Michael137). · Explain WhyNov 30 2022, 6:40 AM This revision was automatically updated to reflect the committed changes.
Comment Actions You may want to check that this kind of automatic dereferencing does not send lldb into a tailspin if the printed data structure is recursive. I know we had problems like that with smart pointer pretty printers. I'd try some code like: #include <ranges> #include <vector> struct A { std::ranges::ref_view<std::vector<A>> a; }; int main() { std::vector<A> v; v.push_back(A{v}); v[0].a = v; // print v ? } Comment Actions
@labath good point E.g., the following would cause such unbounded recursion (didn't find a good way of triggering it using the actual ref_view since it's not default constructible, but it's probably doable): #include <vector> namespace std { inline namespace __1 { namespace ranges { template<typename T> struct ref_view { T* __range_; }; } } } struct Foo { std::ranges::ref_view<std::vector<Foo>> a; }; int main() { Foo f; std::vector<Foo> v; v.push_back(f); std::ranges::ref_view<std::vector<Foo>> r{.__range_ = &v}; f.a = r; return 0; }
Revision Contents
Diff 477440 lldb/source/Plugins/Language/CPlusPlus/CMakeLists.txt
lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
lldb/source/Plugins/Language/CPlusPlus/LibCxx.h
lldb/source/Plugins/Language/CPlusPlus/LibCxxRangesRefView.cpp
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/ranges/ref_view/Makefile
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/ranges/ref_view/TestDataFormatterLibcxxRangesRefView.py
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/ranges/ref_view/main.cpp
|
To be very nitpicking: LLVM style wants full sentences in comments, so let's add a . at the end. :-)