# check\_cxx\_compiler\_flag does not work on unknown warning options of clang

**URL:** https://discourse.cmake.org/t/check-cxx-compiler-flag-does-not-work-on-unknown-warning-options-of-clang/9470
**Category:** Usage
**Tags:** os:linux, os:macos
**Created:** [November 20, 2023, 10:16am UTC](https://discourse.cmake.org/t/check-cxx-compiler-flag-does-not-work-on-unknown-warning-options-of-clang/9470 "2023-11-20T10:16:45Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![swhc](https://discourse.cmake.org/user_avatar/discourse.cmake.org/swhc/32/4016_2.png) [@swhc](https://discourse.cmake.org/u/swhc)
#### Post date: [November 20, 2023, 10:16am UTC](https://discourse.cmake.org/t/check-cxx-compiler-flag-does-not-work-on-unknown-warning-options-of-clang/9470/1 "2023-11-20T10:16:45Z")

</div>

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:

```auto
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:

```auto
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.

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [November 20, 2023, 12:34pm UTC](https://discourse.cmake.org/t/check-cxx-compiler-flag-does-not-work-on-unknown-warning-options-of-clang/9470/2 "2023-11-20T12:34:29Z")

</div>

> [@swhc](#):
>
> Is this expected or there’s a bug here?

Yes, please [file an issue](https://gitlab.kitware.com/cmake/cmake/-/issues) so that a new regex can be added.

---

<div class="post-metadata">

### Author: ![swhc](https://discourse.cmake.org/user_avatar/discourse.cmake.org/swhc/32/4016_2.png) [@swhc](https://discourse.cmake.org/u/swhc)
#### Post date: [November 20, 2023, 2:27pm UTC](https://discourse.cmake.org/t/check-cxx-compiler-flag-does-not-work-on-unknown-warning-options-of-clang/9470/3 "2023-11-20T14:27:48Z")

</div>

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`:

```auto
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 )

```

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [November 20, 2023, 8:15pm UTC](https://discourse.cmake.org/t/check-cxx-compiler-flag-does-not-work-on-unknown-warning-options-of-clang/9470/4 "2023-11-20T20:15:24Z")

</div>

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

---

<div class="post-metadata">

### Author: ![swhc](https://discourse.cmake.org/user_avatar/discourse.cmake.org/swhc/32/4016_2.png) [@swhc](https://discourse.cmake.org/u/swhc)
#### Post date: [November 21, 2023, 1:52am UTC](https://discourse.cmake.org/t/check-cxx-compiler-flag-does-not-work-on-unknown-warning-options-of-clang/9470/5 "2023-11-21T01:52:16Z")

</div>

yes
