cc resolves to /usr/bin/x86_64-linux-gnu-gcc-9
cc --version
cc (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0
The logs probably don’t contain any private information but I’d prefer to do it that way just in case.
I can’t see any additional information in the log with -X.
The project itself is C as are the majority of the source files being analysed.
There is unit test code in C++ which uses:
extern “C”
{
#include “foo.h”
}
My thought is that perhaps this is why C++ rules are triggered for foo.h.
However, foo.h does not itself have an extern “C” block or #ifdef __cplusplus for being compiled as C++.
Reproducing the issue is harder now as I have marked it as a false positive and completed the pull request. C++ smells appear on the master branch (which created by an ‘inscrutible’ azure pipeline) but this is no longer detected as new code.
Snippets from the sonar log and compile-compiles are:
grep -A 2 -B 2 foo.h sonarX.log
11:12:40.364 DEBUG: 'src/main/c/foo/foo_arch.h' indexed with language 'c'
11:12:40.365 DEBUG: 'src/main/c/foo/foo_errn.h' indexed with language 'c'
11:12:40.366 DEBUG: 'src/main/c/foo/foo.h' indexed with language 'c'
11:12:40.366 DEBUG: 'src/main/c/foo/foo_ver.h' indexed with language 'c'
11:12:40.367 DEBUG: 'src/main/c/foo/foo_tick.c' indexed with language 'c'
--
11:12:43.322 DEBUG: 'src/main/c/foo/foo_call.c' generated metadata with charset 'UTF-8'
11:12:43.325 DEBUG: 'src/main/c/foo/foo_user.h' generated metadata with charset 'UTF-8'
11:12:43.327 DEBUG: 'src/main/c/foo/foo.h' generated metadata with charset 'UTF-8'
11:12:43.336 DEBUG: 'src/main/c/foo/foo_misc.c' generated metadata with charset 'UTF-8'
11:12:43.346 DEBUG: 'src/main/c/foo/foo_main.c' generated metadata with charset 'UTF-8'
--
11:12:56.107 DEBUG: /someProject/foo_sonar/src/main/c/foo/foo_stm.h not marked as unchanged: file content changed
11:12:56.107 DEBUG: /someProject/foo_sonar/src/test/c/foo/foo_user_test.cpp not marked as unchanged: file content changed
11:12:56.107 DEBUG: /someProject/foo_sonar/src/main/c/foo/foo.h not marked as unchanged: file content changed
11:12:56.107 DEBUG: /someProject/foo_sonar/src/main/c/foo/foo_main.c not marked as unchanged: file content changed
11:12:56.107 DEBUG: /someProject/foo_sonar/src/main/c/foo/foo_errn.h not marked as unchanged: file content changed
--
11:12:56.404 DEBUG: Blame file (native) src/main/c/foo/foo_call.c
11:12:56.415 DEBUG: Blame file (native) src/main/c/foo/foo_user.h
11:12:56.416 DEBUG: Blame file (native) src/main/c/foo/foo.h
11:12:56.420 DEBUG: Blame file (native) src/main/c/foo/foo_misc.c
11:12:56.429 DEBUG: Blame file (native) src/main/c/foo/foo_main.c
--
11:12:56.653 INFO: CPD Executor 12 files had no CPD blocks
11:12:56.653 INFO: CPD Executor Calculating CPD for 32 files
11:12:56.653 DEBUG: Detection of duplications for /someProject/foo_sonar/src/main/c/foo/foo.h
11:12:56.660 DEBUG: Detection of duplications for /someProject/foo_sonar/src/main/c/foo/foo_io.h
11:12:56.661 DEBUG: Detection of duplications for /someProject/foo_sonar/src/main/c/foo/foo_ip.c
For the test code we of course have both C and C++ in the compile commands:
{
"directory": "/someProject/foo_sonar/target/debug/src/main/c/foo"
"command": "/usr/bin/cc -O2 -g0 -O0 -g3 -fprofile-arcs -ftest-coverage -o CMakeFiles/foo.dir/main.c.o -c /someProject/foo_sonar/src/main/c/foo/main.c",
"file": "/someProject/foo_sonar/src/main/c/foo/main.c"
},
{
"directory": "/someProject/foo_sonar/target/debug/src/test/c/foo",
"command": "/usr/bin/c++ -I/someProject/foo_sonar/src/main/c/foo -g -std=gnu++14 -o CMakeFiles/foo_testsuite1.dir/foo_user_test.cpp.o -c /someProject/foo_sonar/src/test/c/foo/foo_user_test.cpp",
"file": "/someProject/foo_sonar/src/test/c/foo/foo_user_test.cpp"
},
{
"directory": "/someProject/foo_sonar/target/debug/src/test/c/foo",
"command": "/usr/bin/c++ -I/someProject/foo_sonar/src/main/c/foo -g -std=gnu++14 -o CMakeFiles/foo_testsuite1.dir/main.cpp.o -c /someProject/foo_sonar/src/test/c/foo/main.cpp",
"file": "/someProject/foo_sonar/src/test/c/foo/main.cpp"
}
The C code is compiled into a static library which is linked into the test code though sonar only has the #includes to go on.