check_cxx_compiler_flag does not work on unknown warning options of clang

I use check_cxx_compiler_flag to check -Werror=implicit-fallthrough=3 on clang 16.0.6 and it succeeds but actually clang doesn’t support such flags.

Use clang++ -Werror=implicit-fallthough=3 -c A.cc and it gets:

warning: unknown warning option '-Werror=implicit-fallthrough=3'; did you mean '-Werror=implicit-fallthrough'? [-Wunknown-warning-option]
1 warning generated.

I find the implementation of check_cxx_compiler_flag for cxx:

set(${_SRC} "int main() { return 0; }")
set(${_PATTERNS} FAIL_REGEX "command[ -]line option .* is valid for .* but not for C\\+\\+"
      FAIL_REGEX "-Werror=.* argument .* is not valid for C\\+\\+")

The pattern doesn’t match the output.

Is this expected or there’s a bug here?

My cmake version is 3.26.5.

Yes, please file an issue so that a new regex can be added.

Thanks for your reply. I have found one mistake in my CMakeLists.txt that I use check_cxx_compiler_flag() in one loop that uses the same variable as its second parameter, which is cached during the loop, and the incorrect output above is the result of another check.

The pattern I mentioned is also not complete. I run cmake --trace and find the whole pattern is in CMakeCheckCompilerFlagCommonPatterns.cmake:

set(_common_patterns FAIL_REGEX [Uu]nrecogni[sz]ed .*option FAIL_REGEX switch .* is no longer supported FAIL_REGEX unknown .*option FAIL_REGEX optimization flag .* not supported FAIL_REGEX unknown argument ignored FAIL_REGEX ignoring unknown option FAIL_REGEX warning D9002 FAIL_REGEX option.*not supported FAIL_REGEX invalid argument .*option FAIL_REGEX ignoring option .*argument required FAIL_REGEX ignoring option .*argument is of wrong type FAIL_REGEX [Uu]nknown option FAIL_REGEX [Ww]arning: [Oo]ption FAIL_REGEX command option .* is not recognized FAIL_REGEX command option .* contains an incorrect subargument FAIL_REGEX Option .* is not recognized.  Option will be ignored. FAIL_REGEX not supported in this configuration. ignored FAIL_REGEX File with unknown suffix passed to linker FAIL_REGEX [Uu]nknown switch FAIL_REGEX WARNING: unknown flag: FAIL_REGEX Incorrect command line option: FAIL_REGEX Warning: illegal option FAIL_REGEX [Ww]arning: Invalid suboption FAIL_REGEX An invalid option .* appears on the command line FAIL_REGEX WARNING: invalid compiler option )

Ok, so to confirm CMake doesn’t need to change anything here?

yes