Scanner command used when applicable (private details masked) 4.1.0, build-wrapper, mixed solution
Languages of the repository Visual Studio 2026: C++23, C#
Error observed: Specialization of std::hash for user-defined type is reported as an issue.
From “Why is this an issue”:
A program may add a template specialization for any standard library template to namespace std only if the declaration depends on a user-defined type and the specialization meets the standard library requirements for the original template and is not explicitly prohibited.
And as expected, the issue is not raised.
Could you please send us a reproducer?
To generate the reproducer file:
Search in the analysis log for the full path of the source file for which you want to create a reproducer (here, you want to generate the reproducer of a source file that includes the header where hash is specialized). You will have to use exactly this name (same case, / or \…)
Add the reproducer option to the scanner configuration:
sonar.cfamily.reproducer=“Full path to the .source file”
Re-run the scanner to generate a file named sonar-cfamily-reproducer.zip in the project folder.
Please share this file. If you think this file contains private information, let us know, and we’ll send you a private message that will allow you to send it privately.
Hi @JolyLoic
I will try to reduce the solution and reproduce it in a smaller context.
As a workaround I removed namespace std and implement it with fully quallified names (avoid ADL). Then no longer S3470 was reported. We use Visual Studio 2026 but still toolset v143.
I now reduced everything to a single file. In Visual Studio, the error list is empty, but in SonarCloud still the S3470 is reported.
Generating reproducer file failed.
##[error]12:54:35.97 ERROR:
The sonar.cfamily.reproducer property was set but no matching file was found. The property was set to:
‘D:_1\7\s\source\WT.NXG.ComputeEngines\AbstractionsDataTypes.ixx’
The file is available - I could open it with this path on the build server and there was also a hit in the cache. The starting of the path I can’t change it is from the agents variable $(Build.SourcesDirectory).
12:59:29.353 INFO: [2/2] Module scan cache hit for: D:/_1/35/s/source/WT.NXG.ComputeEngines/AbstractionsDataTypes.ixx
12:59:29.356 INFO: Module dependencies for std=C:\Program Files\Microsoft Visual Studio\18\Enterprise\VC\Tools\MSVC\14.44.35207\modules\std.ixx: []
I can now rerun with verbose, hopefully this also helps and send you the reduced repo.
I’ll try it tomorrow - and I have to force for a specific build agent. The number in the path D:_1\7\s depends on the build agent and therefore in the build definition is always used $(Build.SourcesDirectory). But this would be another topic.
Thank you for the reproducer, it allowed me to understand the situation: In your code, the std namespace does not only contain the specialization for std::hash (which is fine), but also a using directive.
Since a using directive is a declaration, it is undefined behavior, which is why the issue is raised.
I have to admit, I didn’t took that into account based on the message and description “Why is this an issue?” While reviewing, it was only a shortcut to avoid writing the fully qualified names of the user defined types.