Fix compilation with gcc12 by backporting change from Geant4 v11
Collection of fixes needed to compile with gcc12. Not yet sure whether or when I want to merge as it is backporting from recent Geant4 release, but want to be able to build in order to check build of other projects depending on Geant4.