# Ambiguous 'data' in global scope

**URL:** <https://root-forum.cern.ch/t/ambiguous-data-in-global-scope/41490>\
**Category:** ROOT\
**Created:** [September 17, 2020, 11:35am UTC](https://root-forum.cern.ch/t/ambiguous-data-in-global-scope/41490 "2020-09-17T11:35:56Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![adye](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/3da27b/32.png) [@adye](https://root-forum.cern.ch/u/adye)\
**Post date:** [September 17, 2020, 11:35am UTC](https://root-forum.cern.ch/t/ambiguous-data-in-global-scope/41490/1 "2020-09-17T11:35:57Z")

</div>

ROOT/Cling seems to include `std::data` in the global scope with GCC8.

```auto
root -b -n
root [0] const char* data= 0;
root [1] data="Hi";
ROOT_prompt_1:1:1: error: reference to 'data' is ambiguous

```

This is new with GCC8 - there was no error with GCC62. I guess this comes with C++17’s std::data(), which would be fine if it stayed in the std namespace, but ROOT seems to import the whole namespace into the command-line’s global scope.

Is there a way to prevent std::data appearing in the global scope? I use `data` in the global scope in some scripts as a convenience for command-line use.

Thanks,  
Tim.

* * *

_ROOT Version:_ 6.20, 6.22  
_Platform:_ x86\_64-centos7-gcc8-opt  
_Compiler:_ gcc 8.3.0

* * *

---

<div class="post-metadata">

**Author:** ![jblomer](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/j/439d5e/32.png) [@jblomer](https://root-forum.cern.ch/u/jblomer)\
**Post date:** [September 17, 2020, 2:53pm UTC](https://root-forum.cern.ch/t/ambiguous-data-in-global-scope/41490/2 "2020-09-17T14:53:28Z")

</div>

I can confirm that the problem is triggered when ROOT is compiled with C++17 support. With C++14 the problem does not appear.

@vvassilev @Axel can you advise?

---

<div class="post-metadata">

**Author:** ![vvassilev](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/v/f0a364/32.png) [@vvassilev](https://root-forum.cern.ch/u/vvassilev)\
**Post date:** [September 17, 2020, 3:33pm UTC](https://root-forum.cern.ch/t/ambiguous-data-in-global-scope/41490/3 "2020-09-17T15:33:47Z")

</div>

Indeed. We do `using namespace std` at ROOT init [https://github.com/root-project/root/blob/master/core/metacling/src/TCling.cxx#L1352](https://github.com/root-project/root/blob/master/core/metacling/src/TCling.cxx#L1352) for backward compatibility from old CINT days.

I do not see an easy way to reverse that without a broader community discussion. Can you rename your variable?

---

<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:** [September 17, 2020, 3:58pm UTC](https://root-forum.cern.ch/t/ambiguous-data-in-global-scope/41490/4 "2020-09-17T15:58:33Z")

</div>

I think there was a proposal to introduce a “strict” interpreter mode that, among other things, removes the implicit `using namespace std`, but I don’t think that’s in, at least at the moment.

---

<div class="post-metadata">

**Author:** ![adye](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/3da27b/32.png) [@adye](https://root-forum.cern.ch/u/adye)\
**Post date:** [September 17, 2020, 4:29pm UTC](https://root-forum.cern.ch/t/ambiguous-data-in-global-scope/41490/5 "2020-09-17T16:29:46Z")

</div>

Thanks for all the feedback.

Having the common parts of the `std` namespace (`cout`, `vector` etc) available in the global namespace is certainly useful.

The problem here is when things get added to the `std` namespace. Maybe I could rename `data` to something else. That would be a nuisance to change everywhere it’s used, but I guess it could be done. But then something else could be broken when something else gets added to `std` later. Hence the advice against `using namespace std`.

Would a useful compromise be to only import the symbols defined in the official C++14 (or other fixed) standard? That would have the bonus of removing internal symbols, and would keep everything people are relying on now, without breaking things like this.

In the meantime, as a workaround, is there a way to remove a symbol if it is already defined in the global namespace. If so, I could remove `data` before defining my own. That would only need one hack, not having to change the name everywhere.

Thanks, Tim.

---

<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:** [September 17, 2020, 6:37pm UTC](https://root-forum.cern.ch/t/ambiguous-data-in-global-scope/41490/6 "2020-09-17T18:37:50Z")

</div>

Hi Tim,

There are a couple of (additional) options at our disposal - we’ll see what we can do about that and let you know.

Cheers, Axel.

---

<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:** [October 1, 2020, 6:37pm UTC](https://root-forum.cern.ch/t/ambiguous-data-in-global-scope/41490/7 "2020-10-01T18:37:52Z")

</div>

Closed on October 1, 2020, 6:37pm UTC

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