False positive cpp:S1000 in source files

Make sure to read this post before raising a thread here:

Then tell us:

  • What language is this for?
    C++
  • Which rule?
    Header files should not contain unnamed namespaces (cpp:S1000)
  • Why do you believe it’s a false-positive/false-negative?
    The rule is triggered on implementation source files.
    It should be only be evaluated in header files.
  • I am using
    • SonarQube Cloud
    • SonarQube for IDE 4.42.0 in VSCode 1.108.2
      • in connected mode with SonarQube Cloud
  • How can we reproduce the problem?

In a .cpp file:

namespace
{
    void f() {}
}

Screenshot as proof:

Forgot to add, this is new behaviour.
Didn’t happen last week.

Thanks for your report!

I tried to reproduce this issue, but was not able to.

Can you share a reproducer? If you want to share it privately, please let me know, then I’ll sent you a DM.

That would probably be best.

Please remind me how to create one.

It’s happening with any namespace in a cpp file now, it seems:

– test.cpp
#include "test.h"

namespace { // internal linkage

uint32_t internalFunc() { return 42; }

} // namespace

uint32_t testFunc() { return internalFunc(); }

– test.h
#include <cstdint>

uint32_t testFunc();

reports Add a name to this namespace.sonarqube(cpp:S1000)

Identifier

sonarsource.sonarlint-vscode

Version

4.44.0

I tried to reproduce it, but I’ve not yet managed.