cling icon indicating copy to clipboard operation
cling copied to clipboard

Fix print check for object that return different types for begin() and end()

Open lackhole opened this issue 1 year ago • 0 comments

  • [x] Checked for duplicates

Describe the bug

A range object that return different types for begin() and end() fails to check if the types is printable.

Expected behavior

printValue_impl<CollectionType> must not fail whether CollectionType is printable or not.

To Reproduce

I'm using C++14 library that provide vccc::views::iota that models std::views::iota. The standard defines that It returns different type for sentinel if it models unbounded iota_view.

Anyway, detailed description is not really necessary because the fix is really simple and intuitive.

Input line

vccc::views::iota(10) | vccc::views::take(4)

Output

In file included from input_line_11:1:
In file included from /Users/yonggyulee/Documents/GitHub/lackhole/xeus-cling/install/include/xcpp/xmime.hpp:16:
/usr/local/include/cling/Interpreter/RuntimePrintValue.h:224:7: error: 'auto' deduced as 'counted_iterator<I>' (aka 'counted_iterator<vccc::ranges::iota_view<int, vccc::unreachable_sentinel_t>::iterator>') in declaration of 'iter' and deduced as 'sentinel<true>' in declaration of 'iterEnd'
      auto iter = obj->begin(), iterEnd = obj->end();
      ^           ~~~~~~~~~~~~            ~~~~~~~~~~
/usr/local/include/cling/Interpreter/RuntimePrintValue.h:241:39: note: in instantiation of function template specialization 'cling::collectionPrinterInternal::printValue_impl<vccc::ranges::take_view<vccc::ranges::iota_view<int>>>' requested here
    return collectionPrinterInternal::printValue_impl(obj);
                                      ^
/Users/yonggyulee/Documents/GitHub/lackhole/xeus-cling/install/include/xcpp/xmime.hpp:49:39: note: in instantiation of function template specialization 'cling::printValue<vccc::ranges::take_view<vccc::ranges::iota_view<int>>>' requested here
        bundle["text/plain"] = cling::printValue(&value);
                                      ^
input_line_24:2:2: note: in instantiation of function template specialization 'xcpp::mime_bundle_repr<vccc::ranges::take_view<vccc::ranges::iota_view<int>>>' requested here
 mime_bundle_repr(*(*(vccc::ranges::take_view<vccc::ranges::iota_view<int, vccc::unreachable_sentinel_t>>**)0x7ff7b1808090));

Setup

  1. Cling version: master
  2. Operating system: macOS 14.0
  3. How you obtained Cling: Build from source

Fix

Just Change the following lines https://github.com/root-project/cling/blob/master/include/cling/Interpreter/RuntimePrintValue.h#L203 https://github.com/root-project/cling/blob/master/include/cling/Interpreter/RuntimePrintValue.h#L224

auto iter = obj->begin(), iterEnd = obj->end();

To

auto iter = obj->begin(); 
auto iterEnd = obj->end();

Created a PR https://github.com/root-project/cling/pull/516

After fix

image

lackhole avatar Jan 21 '24 15:01 lackhole