cpp:S1117 false positive when using the 'not' operator

Hello,

It seems that the detection of S1117 “declaration shadows a local variable” gets fooled when using the not operator. I guess that it thinks that “not” is a type name and that the boolean expression is a variable declaration. That’s a wild guess and my diagnostic may well be off track.

I’m using sonarcloud, so it’s not so easy to build MWE beyond https://sonarcloud.io/project/issues?id=simgrid&issues=AWgE-q2JUMkE2J58J-HH&open=AWgE-q2JUMkE2J58J-HH

Here is a simple code that should reproduce the error:

static int sender(int argc, char** argv) {
  std::vector<simgrid::s4u::CommPtr> pending_comms;
  while(not pending_comms->empty()) { } // I guess that this triggers S1117 even if there is no declaration here
}

Here is another false positive related to the use of ‘not’, against cpp:S1186 this time.
https://sonarcloud.io/project/issues?id=simgrid&issues=AWgE-q_3UMkE2J58J-JS&open=AWgE-q_3UMkE2J58J-JS

bool is_on();
// Method is_off() triggers S1186 "Methods should not be empty" where it's obviously not empty
bool is_off() {
  return not is_on();
}

Hi @mquinson,

yes, you are right, we are not configuring correctly the analyzer in case of operator names, we already have a ticket for it, it is going to fix your false positives.

Hello, thanks for your help.

Is it possible to configure the analyze on our side? We are never using MSVC, but only GCC and clang (plus ICC but we don’t launch the analysis with ICC).

Thanks again,

Hi @mquinson the ticket scope is to properly configure operator names for all supported compilers which include GCC and Clang as well which means you will be fine.

Without resolution of mentioned ticket, the only thing that can be done on your side - is to not use operator names.