12

I have a CMake build using GCC. I generated compile_commands.json then ran clang-tidy but I'm getting hundreds of:

error: unknown warning option '-Wno-maybe-uninitialized'; did you mean '-Wno-uninitialized'? [clang-diagnostic-unknown-warning-option]
error: unknown warning option '-Wno-psabi' [clang-diagnostic-unknown-warning-option]

How can I disable or remove these warnings? I saw clang++ warning: “warning: unknown warning option '-Wno-maybe-uninitialized'” but adding "-Wno-unknown-warning-option" gives me an error:

run-clang-tidy-3.8.py: error: unrecognized arguments: -Wno-unknown-warning-option
parsley72
  • 8,449
  • 8
  • 65
  • 98
  • Possible duplicate of [clang++ warning: "warning: unknown warning option '-Wno-maybe-uninitialized'"](https://stackoverflow.com/questions/41673546/clang-warning-warning-unknown-warning-option-wno-maybe-uninitialized) – Ken Y-N Oct 29 '17 at 23:45
  • But the answer given there doesn't work for clang-tidy. – parsley72 Oct 30 '17 at 00:08
  • If your CMake project adds given compiler options unconditionally, the only thing you can do is probably to fix the CMake project itself. – Tsyvarev Oct 30 '17 at 08:06
  • It's not unconditional - those options are valid with GCC. – parsley72 Oct 30 '17 at 18:26
  • But they are not valid for clang. By "unconditionally" I meant that the project doesn't check compiler before adding the option. Or did you configure the project for gcc, but built it with clang? If so, what else do you want? – Tsyvarev Oct 30 '17 at 19:37
  • I built it with GCC then used the compile_commands.json to run clang-tidy, as I said above. – parsley72 Oct 30 '17 at 22:38

3 Answers3

8

Try appending -extra-arg=-Wno-unknown-warning-option to clang-tidy command line.

Using -extra-arg= asks clang-tidy to pass -Wno-unknown-warning-option to the underlying clang. Otherwise, it tries to interpret it as a clang-tidy flag.

Edit:

The run-clang-tidy.py script supports -extra-arg starting version 5.0. In prior versions, you'd need to edit the script and add that -extra-arg manually.

If you're on Ubuntu 16.04, you can get clang-tidy-5.0 from:
https://www.ubuntuupdates.org/package/xorg-edgers/xenial/main/base/clang-tidy-5.0

valiano
  • 16,433
  • 7
  • 64
  • 79
  • "run-clang-tidy-3.8.py: error: unrecognized arguments: -extra-arg=-Wno-unknown-warning-option". Do I need a newer version of clang-tidy? – parsley72 Nov 01 '17 at 03:44
  • 2
    Right, you would need `run-clang-tidy-5.0.py` for that, if you're running the script (`-extra-arg` is recognized also by `clang-tidy-3.8`, but only in the 5.0 script the argument is recognized by the script and passed on to clang-tidy). – valiano Nov 01 '17 at 06:51
  • Better use `--extra-arg=-Wno-error=unknown-warning-option` – KindDragon Nov 09 '22 at 15:27
2

For me,

set(CMAKE_CXX_CLANG_TIDY "clang-tidy-8;--extra-arg=-Wno-error=unknown-warning-option")

solved the issue when running clang-tidy from within CMake.

tgpfeiffer
  • 1,698
  • 2
  • 18
  • 22
0

I had the same problem when I generated compile_commands.json using GCC. When I used Clang, everything is fine. It seems that clang-tidy/run_clang_tidy.py has a problem with processing compile_commands.json generated by a different compiler than Clang.

jakub gros
  • 11
  • 1
  • 1
  • 3