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
Differential D138558
[lldb][DataFormatter] Add std::ranges::ref_view formatter Michael137 on Nov 23 2022, 3:11 AM. Authored by
Details This patch adds a formatter for std::ranges::ref_view<T>. Testing
Diff Detail
Event TimelineComment Actions Small nitpicks, otherwise good!
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; } |
To be very nitpicking: LLVM style wants full sentences in comments, so let's add a . at the end. :-)