Skip to content

M3-2-1: Do not consider variable template instantiations as a redeclaration with a different type #34

Closed
@lcartey

Description

@lcartey

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()

Metadata

Metadata

Assignees

Labels

Difficulty-LowA false positive or false negative report which is expected to take <1 day effort to addressImpact-Mediumfalse positive/false negativeAn issue related to observed false positives or false negatives.top-25-fpsuser-reportIssue reported by an end user of CodeQL Coding Standards

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions