# C++ std symbols polluting cling

**URL:** <https://root-forum.cern.ch/t/c-std-symbols-polluting-cling/50351>\
**Category:** ROOT\
**Tags:** bug, cling\
**Created:** [June 10, 2022, 1:56pm UTC](https://root-forum.cern.ch/t/c-std-symbols-polluting-cling/50351 "2022-06-10T13:56:31Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![ccorti](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/c/839c29/32.png) [@ccorti](https://root-forum.cern.ch/u/ccorti)\
**Post date:** [June 10, 2022, 1:56pm UTC](https://root-forum.cern.ch/t/c-std-symbols-polluting-cling/50351/1 "2022-06-10T13:56:31Z")

</div>

Dear experts,

when using the interpreter, C++ std symbols pollute the namespace, even if I set `Rint.Includes: 0` in `.rootrc`.  
An example:

```auto
root [0] int data = 1
(int) 1
root [1] data = 2
ROOT_prompt_1:1:1: error: reference to 'data' is ambiguous
data = 2
^
ROOT_prompt_0:1:5: note: candidate found by name lookup is '__cling_N50::data'
int data = 1
    ^
/usr/include/c++/11/bits/range_access.h:319:5: note: candidate found by name lookup is 'std::data'
    data(initializer_list<_Tp> __il) noexcept
    ^
/usr/include/c++/11/bits/range_access.h:290:5: note: candidate found by name lookup is 'std::data'
    data(_Container& __cont) noexcept(noexcept(__cont.data()))
    ^
/usr/include/c++/11/bits/range_access.h:300:5: note: candidate found by name lookup is 'std::data'
    data(const _Container& __cont) noexcept(noexcept(__cont.data()))
    ^
/usr/include/c++/11/bits/range_access.h:310:5: note: candidate found by name lookup is 'std::data'
    data(_Tp (&__array)[_Nm]) noexcept
    ^
root [2] __cling_N50::data
(int) 1

```

Prefixing ` __cling_N50::` every time is really cumbersome, not to mention that the specific `__ cling` namespace changes during the interactive session.  
However, this is even worse if a C++ name is used as name for a TNamed-derived object:

```auto
root [0] 
Attaching file Rates_V0_flux.root as _file0...
(TFile *) 0x556c10f0ab20
root [1] .ls
TFile** Rates_V0_flux.root	
 TFile* Rates_V0_flux.root	
  KEY: TTree	data;1
  KEY: TNtuple	bins;1
root [2] data
ROOT_prompt_2:1:1: error: reference to overloaded function could not be resolved; did you mean to call it?
data
^~~~
/usr/include/c++/11/bits/range_access.h:290:5: note: possible target for call
    data(_Container& __cont) noexcept(noexcept(__cont.data()))
    ^
/usr/include/c++/11/bits/range_access.h:300:5: note: possible target for call
    data(const _Container& __cont) noexcept(noexcept(__cont.data()))
    ^
/usr/include/c++/11/bits/range_access.h:310:5: note: possible target for call
    data(_Tp (&__array)[_Nm]) noexcept
    ^
/usr/include/c++/11/bits/range_access.h:319:5: note: possible target for call
    data(initializer_list<_Tp> __il) noexcept
    ^
root [3] bins
(TNtuple *) 0x556c10cd9c40

```

Now the TTree `data` is not available at all, the only way of using it is to do `auto t = gFile->Get<TTree>("data")`.  
In previous versions of ROOT (like 6.20), I had similar problems with variable names like `y`, but I never had problems with TTrees called `data`.

Best,  
Claudio

* * *

_ROOT Version:_ 6.26/02  
_Git Revision:_ c8d49336  
_Platform:_ Ubuntu  
_Compiler:_ gcc

* * *

---

<div class="post-metadata">

**Author:** ![eguiraud](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/eguiraud/32/32217_2.png) [@eguiraud](https://root-forum.cern.ch/u/eguiraud)\
**Post date:** [June 16, 2022, 7:49am UTC](https://root-forum.cern.ch/t/c-std-symbols-polluting-cling/50351/2 "2022-06-16T07:49:47Z")

</div>

Hi @ccorti ,

thank you for the report and sorry for the high latency, this must have slipped through the cracks.

This is a known annoyance with C++17 builds of ROOT, as that’s the C++ version in which[`std::data`](https://en.cppreference.com/w/cpp/iterator/data) was introduced, and the interpreter has an implicit `using namespace std;`.

There was some discussion about this at [Ambiguous 'data' in global scope](https://root-forum.cern.ch/t/ambiguous-data-in-global-scope/41490) .

@Axel did anything change since then?

Cheers,  
Enrico

---

<div class="post-metadata">

**Author:** ![Axel](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/axel/32/11084_2.png) [@Axel](https://root-forum.cern.ch/u/Axel)\
**Post date:** [June 16, 2022, 8:06am UTC](https://root-forum.cern.ch/t/c-std-symbols-polluting-cling/50351/3 "2022-06-16T08:06:43Z")

</div>

Woops sorry, my fault, this slipped through indeed.

Unconditionally removing `using namespace std` will break the world. Yet I don’t know of any other solution here. Would a `root --puns` (“prevent using namespace std”) be a viable workaround for you? This will actually be quite some work to implement, we know because we tried in the past: there’s a lot of ROOT code that stems from CINT times and relies on finding `vector` and friends. So before embarking there I’d like to see whether that would be a reasonable approach.

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [June 16, 2022, 8:28am UTC](https://root-forum.cern.ch/t/c-std-symbols-polluting-cling/50351/4 "2022-06-16T08:28:23Z")

</div>

Well, this is [a know nuisance](https://root-forum.cern.ch/t/segmentation-violation-when-editing-global-variable-in-compiled-macro/32176/4).

How about instead of injecting “`using namespace std;`”, you inject a precisely described set of “`using std::vector;`” and “`using std::friends;`” (and so on for everything you need, and only for that).

BTW. A similar unsolved deficiency: [“MakeClass and std::”](https://root-forum.cern.ch/t/makeclass-and-std/9826)

---

<div class="post-metadata">

**Author:** ![ccorti](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/c/839c29/32.png) [@ccorti](https://root-forum.cern.ch/u/ccorti)\
**Post date:** [June 16, 2022, 9:12am UTC](https://root-forum.cern.ch/t/c-std-symbols-polluting-cling/50351/5 "2022-06-16T09:12:30Z")

</div>

Well, there is already a system in place to avoid to automatically include std headers: Rint.Includes in rootrc.  
I would expect that if I explicitly ask ROOT not to include any std header, then `using namespace std` should never happen automatically.

---

<div class="post-metadata">

**Author:** ![Axel](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/axel/32/11084_2.png) [@Axel](https://root-forum.cern.ch/u/Axel)\
**Post date:** [June 16, 2022, 9:26am UTC](https://root-forum.cern.ch/t/c-std-symbols-polluting-cling/50351/6 "2022-06-16T09:26:43Z")

</div>

`Rint.Includes: 0` isn’t as effective with C++ modules-based dictionaries, which make “everything” available through a different mechanism.

I’ll look at a `use` of only certain types from `std`.

---

<div class="post-metadata">

**Author:** ![system](https://root-forum.cern.ch/uploads/default/original/3X/e/f/efe4f24398fd8ffeb76bccb6ecc46d9d9c003376.png) [@system](https://root-forum.cern.ch/u/system)\
**Post date:** [June 30, 2022, 9:26am UTC](https://root-forum.cern.ch/t/c-std-symbols-polluting-cling/50351/7 "2022-06-30T09:26:56Z")

</div>

Closed on June 30, 2022, 9:26am UTC

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
