Root branch v6-30-00-patches for C++20 Not Quite Working

I’m afraid I don’t know how to answer that question. Due to how C++ and C++ standard support in the different compilers work, the only way to know whether a certain compiler version works is to try to build ROOT with it, run the test suite and see if it’s green. There might be features that ROOT or a library on which ROOT depends that are required but not supported, and it’s very hard to know until one tests it out.

So I can only report what has been tested, and that’s Ubuntu 22.04 with its default system compiler (gcc 11.4, tested by ROOT’s nightly builds) or Arch Linux with gcc 13.2.1 (tested by me to try to reproduce the problem you reported).

Can reproduce all problems: they seem due to gcc 10.5 + -std=2a

I ran the commands [1] in an Ubuntu 20.04 Docker container, and it reproduces the warnings about the C++ standard you saw and reported in your first thread, so they are most likely due to the mix of gcc 10.5 and c++20.

Patching /root_build/include/RConfigure.h to print out __cplusplus, the message becomes:

warning: The C++ standard in this build (202002L) does not match ROOT configuration (201709L)

Now the question of course is why ROOT thinks it was configured with C++17.
It turns out that fundamentally it’s because clang (the compiler ROOT’s C++ interpreter is based on) and gcc 10.5 disagree on the meaning of -std=c++2a.

Surprisingly, g++ -std=c++2a -c root_src/config/__cplusplus.cxx (which is what ROOT’s CMake runs to figure out what standard it is using) prints 201709L.
On the other hand, using this ROOT build, root -q -e 'printf("%d", __cplusplus)' prints 202002L.

All problems should go away by using gcc 10 with C++17 instead of C++20 or with Ubuntu 22.04 and its system compiler (gcc 11.4).

I’ll leave it to someone in the ROOT team (@bellenot or @Axel maybe?) to comment on whether ROOT’s cmake configuration can be improved to catch more problems than it does now and detect when the compiler does not provide the expected __cplusplus.

On the other hand, the warning we saw was, in a sense, the build system trying to say that there was something funky going on with the compilation toolchain.

I hope this helps.
Cheers,
Enrico


[1]

# gcc 10
apt update -y
apt upgrade -y
apt install -y build-essential
apt install -y gcc-10 g++-10 cpp-10
update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-10 100 --slave /usr/bin/g++ g++ /usr/bin/g++-10 --slave /usr/bin/gcov gcov /usr/bin/gcov-10

# ROOT dependencies from https://root.cern/install/dependencies/#ubuntu-and-other-debian-based-distributions
apt install gfortran libpcre3-dev xlibmesa-glu-dev libglew-dev libftgl-dev libmysqlclient-dev libfftw3-dev libcfitsio-dev graphviz-dev libavahi-compat-libdnssd-dev libldap2-dev python-dev python-numpy libxml2-dev libkrb5-dev libgsl0-dev qtwebengine5-dev
# missing dependencies to build from source:
apt install git cmake python3-dev python3-numpy libxpm-dev libxft-dev 

# ROOT build
git clone --branch v6-30-00-patches --depth 1 https://github.com/root-project/root.git root_src
mkdir root_build && mkdir root_install
cmake -S root_src -B root_build -DCMAKE_INSTALL_PREFIX=root_install -DCMAKE_CXX_STANDARD=20
cmake --build root_build -- -j16 install

P.S.

you said that gcc 10 and above would suffice

I must point out I did not say that :sweat_smile: the quote is “I think you will need at least gcc 10 […] But 12 or 13 would be better” (emphasis added now). And as per the context around that quote, it was a guess based on the C++20 compiler support table that I linked from there.