Compilation errors in TString.h after updating ROOT and GCC

Dear all,

I’m now using ROOT 6.12.07 instead of 5.34.30 and gcc 7.3.1 instead of 4.9.3 on Linux. But I have compilations errors related to TString, see below. Do you know if I have to change my Makefile?

g++ -Wno-deprecated -Wall  -I/cvmfs/cms.cern.ch/slc6_amd64_gcc700/lcg/root/6.12.07-gnimlf5//include -I./ -c -DSTANDALONE=1 -fpic TauDataFormat/TauNtuple/src/DataMCType.cc -o TauDataFormat/TauNtuple/src/DataMCType.o
In file included from /cvmfs/cms.cern.ch/slc6_amd64_gcc700/lcg/root/6.12.07-gnimlf5//include/TString.h:28:0,
                 from ./TauDataFormat/TauNtuple/interface/DataMCType.h:4,
                 from TauDataFormat/TauNtuple/src/DataMCType.cc:1:
/cvmfs/cms.cern.ch/slc6_amd64_gcc700/lcg/root/6.12.07-gnimlf5//include/RStringView.h:67:17: error: expected type-specifier
        operator std::string_view() const { return std::string_view(fData,fLength); }
                 ^~~
In file included from ./TauDataFormat/TauNtuple/interface/DataMCType.h:4:0,
                 from TauDataFormat/TauNtuple/src/DataMCType.cc:1:
/cvmfs/cms.cern.ch/slc6_amd64_gcc700/lcg/root/6.12.07-gnimlf5//include/TString.h:104:13: error: expected type-specifier
    operator std::string_view() const { return std::string_view(Data(),fExtent); }
             ^~~
/cvmfs/cms.cern.ch/slc6_amd64_gcc700/lcg/root/6.12.07-gnimlf5//include/TString.h:257:23: error: 'string_view' in namespace 'std' does not name a type
    TString(const std::string_view &sub);
                       ^~~~~~~~~~~
/cvmfs/cms.cern.ch/slc6_amd64_gcc700/lcg/root/6.12.07-gnimlf5//include/TString.h:293:37: error: 'string_view' in namespace 'std' does not name a type
    TString    &operator=(const std::string_view &s);
                                     ^~~~~~~~~~~
/cvmfs/cms.cern.ch/slc6_amd64_gcc700/lcg/root/6.12.07-gnimlf5//include/TString.h:420:9: error: 'string_view' in namespace 'std' does not name a type
    std::string_view View() const { return std::string_view(GetPointer(),Length()); }
         ^~~~~~~~~~~
In file included from ./TauDataFormat/TauNtuple/interface/DataMCType.h:4:0,
                 from TauDataFormat/TauNtuple/src/DataMCType.cc:1:
/cvmfs/cms.cern.ch/slc6_amd64_gcc700/lcg/root/6.12.07-gnimlf5//include/TString.h:785:53: error: 'string_view' in namespace 'std' does not name a type
 inline Bool_t operator==(const char *s1, const std::string_view &s2)
                                                     ^~~~~~~~~~~
/cvmfs/cms.cern.ch/slc6_amd64_gcc700/lcg/root/6.12.07-gnimlf5//include/TString.h:785:68: error: 'Bool_t operator==(const char*, const int&)' must have an argument of class or enumerated type
 inline Bool_t operator==(const char *s1, const std::string_view &s2)
                                                                    ^
/cvmfs/cms.cern.ch/slc6_amd64_gcc700/lcg/root/6.12.07-gnimlf5//include/TString.h:790:37: error: 'string_view' in namespace 'std' does not name a type
 inline Bool_t operator==(const std::string_view &s1, const char *s2)
                                     ^~~~~~~~~~~
/cvmfs/cms.cern.ch/slc6_amd64_gcc700/lcg/root/6.12.07-gnimlf5//include/TString.h:790:68: error: 'Bool_t operator==(const int&, const char*)' must have an argument of class or enumerated type
 inline Bool_t operator==(const std::string_view &s1, const char *s2)
                                                                    ^
/cvmfs/cms.cern.ch/slc6_amd64_gcc700/lcg/root/6.12.07-gnimlf5//include/TString.h:803:37: error: 'string_view' in namespace 'std' does not name a type
   std::string printValue(const std::string_view* val);

If I’m not mistaken, std::string_view is a C++17 feature and GCC 7.3 defaults to C++14. May you try cmake -DCMAKE_CXX_VERSION=c++17 . in the build directory then build root again?

If that doesn’t work. Please try install clang sudo apt install clang, set clang as compiler cmake -DCMAKE_CXX_COMPILER=clang++ . then build root.

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

We have a back port of std::string_view so that we can use it even with older C++ standard. However, the detection of whether we need to use the back port or not is only done once per build area. (So when switching compiler version or which standard you use, you need to start fresh).

Strangely the error comes from our backport:

6.12.07-gnimlf5//include/RStringView.h:67:17: error: expected type-specifier
        operator std::string_view() const { return std::string_view(fData,fLength); }
                 ^~~

I can’t remember what the default standard for gcc 7.3.1 … Did you configure to use any specific standard?