I am using SonarQube 9.9 (build 65466) Enterprise Edition. We have enabled the rule cpp:S978 in our projects, but, unfortunately, it is too coarse for our purposes.
We would like to have SonarQube check for reserved identifiers as per the C++ standard (see, for example, Identifiers - cppreference.com )
This means (quote):
identifiers with a double underscore anywhere;
identifiers that begin with an underscore followed by an uppercase letter;
in the global namespace, identifiers that begin with an underscore.
SonarQube already implements this in cpp:S978, but with the following additions:
C standard library function names
That “defined” is included is not a major problem for us, but the C stdlib function names part is. We do have member functions on objects that are named like C functions, for example “log()”. Also, some of the libraries we use do this - for example, spdlog → spdlog/logger.h at b25aaecf6aae27a3ccae860fadb952b3cfb40dd1 · gabime/spdlog · GitHub
So it would not make a lot of sense for us to refrain from using the “log()” function name for ourselves when we have to call spdlog::logger::log() anyway.
I do think that declaring a member function “log()” is not a big issue, because we are doing C++ and we forbid ourselves from using the free-standing C library functions anyway per our code style. This means that, if we would use log() for example, we would use std::log from and not log from <math.h>. This is also covered by SonarQube in rule cpp:S1051.
Might I propose that cpp:S978 is split into two parts that can be separately enabled, one checking for C stdlib name clashes (for the people that want this check) and one that just checks the actual language rules?