Possible solution might be using mambaforge, as mentioned in this thread
I was able to easily install latest version of gcc in Ubuntu with following commands:
curl -L -O "https://github.com/conda-forge/miniforge/releases/latest/download/Mambaforge-$(uname)-$(uname -m).sh"
bash Mambaforge-$(uname)-$(uname -m).sh
source mambaforge/bin/activate
mamba create -n gcctest gxx -c conda-forge
conda activate gcctest
I guess that this should work in Centos also.
So you could get latest gcc version in this way and try to build ROOT with it.