Rootcling and std::span<T>

Hello,

Is there any support for std::span in ROOT 6.32.04. It seems rootcling doesn’t recognize it.
I just want to use std::span as a template and CMAKE_COMPILER_STANDARD is set to 23.

$> /usr/local/root/bin/rootcling -v2 -f MyDict.cxx -cxxmodule -s /path/to/install/mylib.dylib -I [...] -I/path/to/include [..MyHeaders...] LinkDef.h
error: no template named 'span' in namespace 'std'
        std::span<double> data;
        ~~~~~^
Error: /usr/local/root/bin/rootcling: compilation failure (/path/to/build/libXXX_dictUmbrella.h)

I can reproduce this locally, but my cling is configured to use C++17. If you use the --v4 verbosity level, what is the output regarding the C++ standard? (use for example 2>&1 | grep CPlusPlus)

Info: CPlusPlus11 = 1 // C++11
Info: CPlusPlus14 = 1 // C++14
Info: CPlusPlus17 = 1 // C++17
Info: CPlusPlus20 = 0 // C++20
Info: CPlusPlus23 = 0 // C++23
Info: CPlusPlus26 = 0 // C++26

Thinking about it, even if cling supports C++20 in your case, there might be a problem if you wanted to use the span for I/O:
Writing would be kind of easy; one could write a span like one would write an array or a vector.
But what would you expect for reading a span? Since it doesn’t own the memory, where should ROOT’s I/O system allocate the memory?

Hi Stephan,

Thank you so much for your insights. I think I have caught the origin of the issue.
In my cmake project, I was setting CXX_STANDARD to 20 because std::span is only available from CXX20.

However in cmake, loading ROOT (built with CXX17) doesn’t check for conflict between standards. (I eventually got confused, because I had same results as you using --v4. and this was the reason)

Info: CPlusPlus11 = 1 // C++11
Info: CPlusPlus14 = 1 // C++14
Info: CPlusPlus17 = 1 // C++17
Info: CPlusPlus20 = 0 // C++20
Info: CPlusPlus23 = 0 // C++23
Info: CPlusPlus26 = 0 // C++26

OK, that makes sense. Thank you!