Ambiguous 'data' in global scope

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

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


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?

Indeed. We do using namespace std at ROOT init 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?

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.

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.

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.

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