cpp:S1000 Header files should not contain unnamed namespaces in with C++ modules (C++23)

Template for a good new topic, formatted with Markdown:

  • ALM used:Azure DevOps
  • CI system used: Azure DevOps, self hosted agent
  • Scanner command used when applicable: SonarCloudAnalyze@4.2.5
  • Languages of the repository C++23, C#
  • Error observed (wrap logs/code around with triple quotes ``` for proper formatting)
  • Steps to reproduce
    To keep the logger local to the tranlsation unit, it is defined in an anonymous workspace inside the ixx module partion file. This is reported as Add a name to this namespace.
export module MyModule1::MyPartition1; 

import MyLogging;

namespace
{
    const auto logger = ...
}

namespace MyNameSpace1
{
   export class ... {
       ...
       logger->LogError(...)
       ...
  } 
}

The same issue is reported, if the anonymous namespace is placed inside

namespace MyNameSpace1
{
   namespace
   {
       const auto logger = ...
   }
   ....  
}

Hi @milbrandt ,

Apologies for the late reply and thanks for reporting this issue.

I was able to reproduce it on my side with the following minimal example:

// Module.cppm
export module mod;

namespace { // FP S1000:Add a name to this namespace.
}
// Implementation.cpp
module mod;

To clarify. Does your module interface unit also have a corresponding module implementation unit? From my debugging, this is the necessary condition to trigger this false positive.

In any case, I’ve created a ticket to fix this. But let me know if your case is actually different.

Hi @lijun.chen
in my solution (MSBuild, MSVC 19.44, Visual Studio 2026) I get this error in 3 ixx files - all without implementation unit cpp.

The 3 ixx are partitions of the same module. Other partitions of this module have implementation units.

Thanks for the additional details.

Another question: Are you getting this issue from SonarQube IDE only? Or you get this issue also in a normal CI scan on SonarQube Cloud?

@lijun.chen I observed it in SonarQube Cloud (not public unfortunately), I assume background task id AZ9lI41k4qcSY7bcfxHN

@milbrandt Thanks for confirming.

At this point, I’d like to ask you to generate a reproducer so that I can investigate further on this issue. Thanks!