| Summary: | Building G4.11 on Windows with VS2019 above v16.1 | ||
|---|---|---|---|
| Product: | Geant4 | Reporter: | Thomas Frosio <thomas.frosio> |
| Component: | global | Assignee: | Ben Morgan <Ben.Morgan> |
| Status: | CLOSED FIXED | ||
| Severity: | normal | ||
| Priority: | P4 | ||
| Version: | 11.0 | ||
| Hardware: | PC | ||
| OS: | Windows | ||
| URL: | https://geant4-forum.web.cern.ch/t/building-g4-11-on-windows-with-vs2019-v16-11-8/6762/2 | ||
| Attachments: |
Patch
Patch for G4String C2666 errors on MSVC |
||
|
Description
Thomas Frosio
2022-01-07 19:30:42 CET
Thanks for the patch - we'll take a look. Created attachment 750 [details]
Patch for G4String C2666 errors on MSVC
We've reproduced and identified the heart of the problem, which is down to G4String providing both an implicit conversion operator to const char* and subscript operator. MSVC looks to be the first to be strict about this, or older/other compilers can work around it. The overload that causes confusion is actually the builtin operator[](const char*, int) which is considered due to GString's conversion to const char*. Rather than patch calls to G4String::operator[](size_type) with G4String::at(size_type), an additional overload G4String::operator[](int) is provided, resolving the ambiguity, and is attached here. This is purely a workaround until removal of the const char* conversion operator is removed, but has been tested to work on both latest Visual Studio 2019 and 2022, with no issues identified on other platforms/compilers. Whoops, forgot to say of course this fix will be in the next patch to 11.0, due in the next couple of weeks! |