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
With the following code as an example
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:
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 - Clang tidy part III · Detect1ve/CPlusPlus-Developer.-Professional@262c3e7 · GitHub
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:
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:
/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?