# Incorrect log output during clang-tidy error with -p option

**URL:** https://discourse.cmake.org/t/incorrect-log-output-during-clang-tidy-error-with-p-option/15106
**Category:** Usage
**Tags:** os:linux, gen:ninja
**Created:** [August 23, 2025, 2:20pm UTC](https://discourse.cmake.org/t/incorrect-log-output-during-clang-tidy-error-with-p-option/15106 "2025-08-23T14:20:13Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Detect1ve](https://discourse.cmake.org/user_avatar/discourse.cmake.org/detect1ve/32/5780_2.png) [@Detect1ve](https://discourse.cmake.org/u/Detect1ve)
#### Post date: [August 23, 2025, 2:20pm UTC](https://discourse.cmake.org/t/incorrect-log-output-during-clang-tidy-error-with-p-option/15106/1 "2025-08-23T14:20:13Z")

</div>

So, in continuation of issue 27160

# TL;DR

Using the `Ninja` generator, I see an incorrect command for clang-tidy launch with the `-p` option in case of error. Is it a problem on the `Ninja` side or `CMake`? It appears that the command displayed during the build and the command that is actually executed are different.

# Description

I want to add `-fconcepts` as a compile option for `GCC` and use `clang-tidy`. To hide the `-fconcepts` option in `clang-tidy`, I used the `-p` option as described here: - [https://cmake.org/cmake/help/latest/prop\_tgt/LANG\_CLANG\_TIDY.html](https://cmake.org/cmake/help/latest/prop_tgt/LANG_CLANG_TIDY.html)  
With the following code as an example

```cmake
set_target_properties(main PROPERTIES CXX_CLANG_TIDY "clang-tidy;--warnings-as-errors=*;-checks=llvmlibc-implementation-in-namespace;-p;${CMAKE_BINARY_DIR}"

```

I got the following error and log:

```auto
FAILED: [code=1] HW_4/CMakeFiles/print_ip.dir/src/main.cpp.o 
/usr/local/bin/cmake -E __run_co_compile --tidy="/usr/bin/clang-tidy;--use-color;--warnings-as-errors=*;-checks=llvmlibc-implementation-in-namespace;-p;/home/runner/work/CPlusPlus-Developer.-Professional/CPlusPlus-Developer.-Professional/build;--extra-arg-before=--driver-mode=g++" --source=/home/runner/work/CPlusPlus-Developer.-Professional/CPlusPlus-Developer.-Professional/HW_4/src/main.cpp -- /usr/bin/c++ -I/home/runner/work/CPlusPlus-Developer.-Professional/CPlusPlus-Developer.-Professional/HW_4/include -std=c++26 -fdiagnostics-color=always -Wall -Wextra -pedantic -fconcepts -MD -MT HW_4/CMakeFiles/print_ip.dir/src/main.cpp.o -MF HW_4/CMakeFiles/print_ip.dir/src/main.cpp.o.d -o HW_4/CMakeFiles/print_ip.dir/src/main.cpp.o -c /home/runner/work/CPlusPlus-Developer.-Professional/CPlusPlus-Developer.-Professional/HW_4/src/main.cpp
/home/runner/work/CPlusPlus-Developer.-Professional/CPlusPlus-Developer.-Professional/HW_4/src/main.cpp:25:5: error: declaration must be enclosed within the 'LIBC_NAMESPACE' namespace [llvmlibc-implementation-in-namespace,-warnings-as-errors]
   25 | int main()

```

Link to the full log - [https://github.com/Detect1ve/CPlusPlus-Developer.-Professional/actions/runs/17176111583/job/48732188283?pr=45](https://github.com/Detect1ve/CPlusPlus-Developer.-Professional/actions/runs/17176111583/job/48732188283?pr=45)

So, there is a `-p` option, but still I see the following `-- /usr/bin/c++ -I/home/runner/work/CPlusPlus-Developer.-Professional/CPlusPlus-Developer.-Professional/HW_4/include -std=c++26 -fdiagnostics-color=always -Wall -Wextra -pedantic -fconcepts -MD -MT HW_4/CMakeFiles/print_ip.dir/src/main.cpp.o -MF`  
which is strange, because according to the documentation, the behaviour should be different:

```auto
If the specified `clang-tidy` command line includes the `-p` option, it will be invoked without `--` and the full compiler command line.

```

Also, I think the log output command can be used as a command to run in the terminal(with some changes, of course), and when I do that, I get a different output:

```auto
/usr/bin/clang-tidy --use-color --warnings-as-errors=* -checks=llvmlibc-implementation-in-namespace -p /home/runner/work/CPlusPlus-Developer.-Professional/CPlusPlus-Developer.-Professional/build /home/runner/work/CPlusPlus-Developer.-Professional/CPlusPlus-Developer.-Professional/HW_4/src/main.cpp -- --driver-mode=g++ -I/home/runner/work/CPlusPlus-Developer.-Professional/CPlusPlus-Developer.-Professional/HW_4/include -std=c++26 -fdiagnostics-color=always -Wall -Wextra -pedantic -fconcepts
error: unknown argument: '-fconcepts' [clang-diagnostic-error] <---- here the difference!!!
HW_4/src/main.cpp:25:5: error: declaration must be enclosed within the 'LIBC_NAMESPACE_DECL' namespace [llvmlibc-implementation-in-namespace,-warnings-as-errors]
   25 | int main()
      | ^

```

Is this expected behavior?

---

<div class="post-metadata">

### Author: ![craig.scott](https://discourse.cmake.org/user_avatar/discourse.cmake.org/craig.scott/32/20_2.png) [@craig.scott](https://discourse.cmake.org/u/craig.scott)
#### Post date: [August 23, 2025, 9:47pm UTC](https://discourse.cmake.org/t/incorrect-log-output-during-clang-tidy-error-with-p-option/15106/2 "2025-08-23T21:47:19Z")

</div>

When you use the `-p` option, CMake will tell clang-tidy to use the `compile_commands.json` file to get the full compiler command line instead of whatever follows after the `--`. If you’ve added `-fconcepts` to the compile command, it will be included in the `compile_commands.json` as well.

---

<div class="post-metadata">

### Author: ![Detect1ve](https://discourse.cmake.org/user_avatar/discourse.cmake.org/detect1ve/32/5780_2.png) [@Detect1ve](https://discourse.cmake.org/u/Detect1ve)
#### Post date: [August 23, 2025, 10:19pm UTC](https://discourse.cmake.org/t/incorrect-log-output-during-clang-tidy-error-with-p-option/15106/3 "2025-08-23T22:19:16Z")

</div>

It’s worth mentioning here that I use a trick with changing `compile_commands.json` by removing `-fconcepts` from there so that `clang-tidy` can run successfully, so there is no mention of `-fconcepts` inside compile\_commands.json, **but there is in the log**.

Okay, let’s clarify another point:  
Are you saying that `CMake` will implicitly exclude everything that comes after `--`, but will still show the full compiler command line in the log in case of an analysis `clang-tidy` error?

Is this really a good solution/approach? I think it may not be very clear.

If I explained the situation poorly, I’m ready to try to explain it in another way 🙂

---

<div class="post-metadata">

### Author: ![craig.scott](https://discourse.cmake.org/user_avatar/discourse.cmake.org/craig.scott/32/20_2.png) [@craig.scott](https://discourse.cmake.org/u/craig.scott)
#### Post date: [August 24, 2025, 10:06pm UTC](https://discourse.cmake.org/t/incorrect-log-output-during-clang-tidy-error-with-p-option/15106/4 "2025-08-24T22:06:18Z")

</div>

> It’s worth mentioning here that I use a trick with changing `compile_commands.json`…

Welcome to the land of “unsupported, you’re on your own now”. 😉

> [@Detect1ve](#):
>
> Are you saying that `CMake` will implicitly exclude everything that comes after `--`, but will still show the full compiler command line in the log in case of an analysis `clang-tidy` error?

The documentation for [`<LANG>_CLANG_TIDY`](https://cmake.org/cmake/help/latest/prop_tgt/LANG_CLANG_TIDY.html) says the following:

> Changed in version 3.25: If the specified `clang-tidy` command line includes the `-p` option, it will be invoked without `--` and the full compiler command line. `clang-tidy` will look up the source file in the specified compiler commands database.

Maybe that could be worded better, but what it means is that `clang-tidy` is invoked with the compiler command from `compile_comands.json`, and everything from the `--` and what comes after it in the log is ignored for `clang-tidy`. Note that what you see in the log is still what will be used for the actual compilation. The two should agree (command line and `compile_commands.json`), but this behavior was added to work around a bug in `clang-tidy` for special cases where it can sometimes make wrong decisions about the compiler if fed the compiler command line directly.
