In this case, double definition issues should be prevented by using anonymous namespaces. However, when running this code through cppcheck (version 2.9) I get a ctuOneDefinitionRuleViolation. When changing the anonymous namespaces to named namespaces, the warning goes away, When using non-template classes this principle seems to work correctly, but when using templates, something seems to fail.
When looking at the cppcheck debug output, cppcheck sewems to incorrectly create a template instance definition outside of the anonymous namespace. This goes well with named namespaces, but goes wrong for anonymous namespaces. It should probably define the instantiation of the class using class ::newtest<int></int>
Consider the following 2 source files, defining a template class called test.
File main.cpp
File other.cpp
In this case, double definition issues should be prevented by using anonymous namespaces. However, when running this code through cppcheck (version 2.9) I get a ctuOneDefinitionRuleViolation. When changing the anonymous namespaces to named namespaces, the warning goes away, When using non-template classes this principle seems to work correctly, but when using templates, something seems to fail.
When looking at the cppcheck debug output, cppcheck sewems to incorrectly create a template instance definition outside of the anonymous namespace. This goes well with named namespaces, but goes wrong for anonymous namespaces. It should probably define the instantiation of the class using class ::newtest<int></int>
Last edit: Martijn 2022-09-29