Skip to content

Commit 6f083f6

Browse files
committed
[cling] Add back suppport for printing std::array
1 parent 977b48c commit 6f083f6

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

interpreter/cling/include/cling/Interpreter/RuntimePrintValue.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,13 @@ namespace cling {
200200
isMap(const T* M, const typename T::mapped_type* V = 0) { return M; }
201201
static constexpr const void* isMap(const void* M) { return nullptr; }
202202
};
203+
template <typename CollectionType>
204+
struct is_std_array : public std::false_type {};
205+
206+
template <typename T, std::size_t N>
207+
struct is_std_array<std::array<T, N>> : public std::true_type {};
203208

204-
// vector, set, deque etc.
209+
// vector, set, deque, array etc.
205210
template <typename CollectionType>
206211
inline auto printValue_impl(
207212
const CollectionType* obj,
@@ -220,6 +225,10 @@ namespace cling {
220225
// infinite recursion. This occurs with scalar values in nlohmann::json
221226
auto printWithRecursionGuard = [obj](const auto* ptr,
222227
const void* M) -> std::string {
228+
// std::array begins at the same location as the object itself, but it
229+
// is not infinitely recursive
230+
if constexpr (is_std_array<CollectionType>::value)
231+
return printValue(ptr, M);
223232
if (static_cast<const void*>(ptr) == static_cast<const void*>(obj))
224233
return "<recursion detected>";
225234
return printValue(ptr, M);

interpreter/cling/test/Prompt/ValuePrinter/Collections.C

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
// RUN: cat %s | %cling -Xclang -verify 2>&1 | FileCheck %s
1111

12+
#include <array>
1213
#include <string>
1314
#include <tuple>
1415
#include <vector>
@@ -77,7 +78,15 @@ S
7778
// CHECK-NEXT: (std::set<std::pair<int, std::string> > &) { {4 , "0"}, {14 , "1"}, {24 , "2"}, {34 , "3"}, {44 , "4"} }
7879

7980
MM
80-
// (std::map<std::string, std::map<int, std::pair<int, std::string> > > &) { "0" => { 0 => {0 , "00"}, 1 => {3 , "05"}, 2 => {6 , "010"} }, "1" => { 0 => {0 , "10"}, 1 => {3 , "15"}, 2 => {6 , "110"} }, "2" => { 0 => {0 , "20"}, 1 => {3 , "25"}, 2 => {6 , "210"} }, "3" => { 0 => {0 , "30"}, 1 => {3 , "35"}, 2 => {6 , "310"} }, "4" => { 0 => {0 , "40"}, 1 => {3 , "45"}, 2 => {6 , "410"} } }
81+
// CHECK-NEXT: (std::map<std::string, std::map<int, std::pair<int, std::string> > > &) { "0" => { 0 => {0 , "00"}, 1 => {3 , "05"}, 2 => {6 , "010"} }, "1" => { 0 => {0 , "10"}, 1 => {3 , "15"}, 2 => {6 , "110"} }, "2" => { 0 => {0 , "20"}, 1 => {3 , "25"}, 2 => {6 , "210"} }, "3" => { 0 => {0 , "30"}, 1 => {3 , "35"}, 2 => {6 , "310"} }, "4" => { 0 => {0 , "40"}, 1 => {3 , "45"}, 2 => {6 , "410"} } }
82+
83+
std::array<int, 3> Arr{42, 43, 44};
84+
Arr
85+
// CHECK-NEXT: (std::array<int, 3> &) { 42, 43, 44 }
86+
87+
std::array<std::array<int, 2>, 3> ArrArr{{{1, 2}, {3, 4}, {5, 6}}};
88+
ArrArr
89+
// CHECK-NEXT: (std::array<std::array<int, 2>, 3> &) { { 1, 2 }, { 3, 4 }, { 5, 6 } }
8190

8291
// expected-no-diagnostics
8392
.q

0 commit comments

Comments
 (0)