Dear Geant4 team,
I am trying to update my previous installation of GEANT4 (G4.11preview) to the released one.
On Ubuntu20.04, everything goes well.
However, on windows, I have some problems with VS2019 v16.11.8.
Indeed, the compiler gives me multiple errors C2666 for some .icc files, in particular for G4String.icc.
For the example of G4String.icc, compiler seems to not accept the overloading of the “starts_with” function as it is pointing line 236 which corresponds to the second definition of:
What versions for MSVC etc are printed when you run CMake to configure Geant4? It’s usually the first few lines like:
-- Selecting Windows SDK version 10.0.18362.0 to target Windows 10.0.19042.
-- The C compiler identification is MSVC 19.25.28612.0
-- The CXX compiler identification is MSVC 19.25.28612.0
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.25.28610/bin/Hostx64/x64/cl.exe
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.25.28610/bin/Hostx64/x64/cl.exe - works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.25.28610/bin/Hostx64/x64/cl.exe
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.25.28610/bin/Hostx64/x64/cl.exe - works
Selecting Windows SDK version 10.0.18362.0 to target Windows 10.0.22000.
The C compiler identification is MSVC 19.29.30138.0
The CXX compiler identification is MSVC 19.29.30138.0
Detecting C compiler ABI info
Detecting C compiler ABI info - done
Check for working C compiler: D:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x86/cl.exe - skipped
Detecting C compile features
Detecting C compile features - done
Detecting CXX compiler ABI info
Detecting CXX compiler ABI info - done
Check for working CXX compiler: D:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x86/cl.exe - skipped
Detecting CXX compile features
Detecting CXX compile features - done
Checking C++ feature CXXSTDLIB_FILESYSTEM_NATIVE - Success
Reusing dataset G4NDL (4.6)
Reusing dataset G4EMLOW (8.0)
Reusing dataset PhotonEvaporation (5.7)
Reusing dataset RadioactiveDecay (5.6)
Reusing dataset G4PARTICLEXS (4.0)
Reusing dataset G4PII (1.3)
Reusing dataset RealSurface (2.2)
Reusing dataset G4SAIDDATA (2.0)
Reusing dataset G4ABLA (3.1)
Reusing dataset G4INCL (1.0)
Reusing dataset G4ENSDFSTATE (2.3)
Reusing dataset G4TENDL (1.4)
The following Geant4 features are enabled:
CMAKE_CXX_STANDARD: Compiling against C++ Standard '17'
GEANT4_BUILD_MULTITHREADED: Build multithread enabled libraries
GEANT4_USE_INVENTOR_QT: Build OpenInventor Qt Driver
GEANT4_USE_QT: Build Geant4 with Qt support
GEANT4_USE_OPENGL_WIN32: Build OpenGL driver with Win32 support
GEANT4_USE_QT3D: Build Geant4 Qt3D driver
Configuring done
Generating done
Thanks! I think our Windows testing node is probably behind the version that introduced the update mentioned on Compiler Error C2666 | Microsoft Docs
We’ll get that updated and a fix prepared (could you also post the full compiler error message here please?). In the meantime, it’s probably sufficient to remove all bar the declarations/definitions of:
I want to mention that it is not only linked to G4String.icc.
I found the following files with issues but did not finish the compilation yet so it might not be the full list. I will then update my post in the next hours (UPDATED NOW):
I think there should be an option in MSVC to neglect those errors since it is working well with previous versions. It will be quite complex to modify all the files. Also this C2666 does not make sense to me since the compiler should understand the overload correctly.
I have checked random classes in my list above and the errors in those classes come from the use of G4String so, everything seems to be linked to G4String.icc
I will summarize here the error and how I fixed it.
When compiling GEANT4.11.0 on windows using VS2019 v16.11.8 (in fact it will happen with all versions above 16.1), the compiler provides multiple errors C2666 indicating for operator[] from G4String: number overloads have similar conversions.
The way I fixed the problem is detailed below. Please note that I also tried to compile the code with my modifications on Linux and to execute it on a simple example with success.
In the different files I mentioned in my previous message above, the problem comes from the use of G4String::operator[] instead of G4String::at()
At multiple locations in the code, one can find (for example)
if (!(jslash == indx && bpath[indx] == '/'))
// Whereas the correct use should be
if (!(jslash == indx && bpath.at(indx) == '/'))
Please find below a patch that I will also submit on Bugzilla. G4_11_patch_String.txt (21.8 KB)