Closed
Description
Affected rules
M3-2-1
Description
In CodeQL variable templates are represented by multiple different variables (an uninstantiated copy, plus a copy for each instantiation). As each of these can have a different type, they currently cause false positives for M3-2-1
, which is about finding redeclarations of the same object with incompatible types.
The easiest way to exclude templates is to remove versions from template instantiations:
not decl1.isFromTemplateInstantiation(_) and
not decl2.isFromTemplateInstantiation(_)
While we are making modifications to this query, there are a few other changes we should make:
- Exclude member variables, as they are not "objects".
- Provide a link to each of the types so that the user can verify that the types are different. This is important because the two types may have the same name, but may be defined differently.
select decl1, "The object $@ of type $@ is not compatible with re-declaration $@ of type $@", decl1, decl1.getName(), decl1.getType(), decl1.getType().toString(), decl2, decl2.getName(), decl2.getType(), decl2.getType().toString()