Gfortran 15.1 Wexternal-argument-mismatch bug

Gfortran 15.1 has a bug with the -Wexternal-argument-mismatch flag. This flag is implicitly included in the -Wall option. In Gfortran 15.1–fixed in Gfortran 15.2–the -Wexternal-argument-mismatch warning causes compilation to fail on correct code. To work around this bug, suggest in the build system such as CMake to detect GCC 15.1 and disable the -Wexternal-argument-mismatch warning. It’s also relevant to consider if -Wall is a flag one wants to automatically set for the default end-user build, as such a bug could happen for future versions of GCC as well.

In CMake, detect GCC 15.1 and disable the problem flag:

if(CMAKE_Fortran_COMPILER_ID STREQUAL "GNU" AND
   CMAKE_Fortran_COMPILER_VERSION VERSION_GREATER_EQUAL "15.0" AND
   CMAKE_Fortran_COMPILER_VERSION VERSION_LESS "15.2"
   )
  add_compile_options($<$<COMPILE_LANGUAGE:Fortran>:-Wno-external-argument-mismatch>)
endif()