cling
cling copied to clipboard
References are not part of the printed type
I find it unexpected that references are not part of the printed type. For example:
$ cling --version
0.8~dev
$ cling -std=c++17
****************** CLING ******************
* Type C++ code and press enter to run it *
* Type .q to exit *
*******************************************
[cling]$ constexpr char s1[] = "abc";
[cling]$ constexpr decltype(auto) s2 = "abc";
[cling]$ s1
(const char [4]) "abc"
[cling]$ s2
(char const[4]) "abc"
[cling]$ #include <type_traits>
[cling]$ std::is_same_v<decltype(s1), decltype(s2)>
(const bool) false
Notice how the displayed types are equivalent but in reality the types are not actually equivalent. s2
actually is missing a reference in the printed type (s2
is of type char const (&)[4]
). The first time I saw this, I was really confused.
The same is true for more straight-forward situations like this:
$ cling
****************** CLING ******************
* Type C++ code and press enter to run it *
* Type .q to exit *
*******************************************
[cling]$ int i1{};
[cling]$ int &i2 = i1;
[cling]$ i1
(int) 0
[cling]$ i2
(int) 0
Is this a bug or intended behavior? Is there a way to print a type including its references?