Files
codeql/cpp/ql/src/Likely Bugs/Arithmetic/PointlessSelfComparison.ql
Jonas Jensen 97cc0ebc8c C++: Suppress PointlessSelfComparison on templates
It's a bit crude to suppress all results in instantiations, but we're
already using this kind of suppression in `PointlessComparison.ql`
(without the `Self`) because there is no convenient alternative. It
means we lose some good results but also suppress a new false positive
in Boost that surfaced after we added support for non-type template
parameters.
2019-11-11 14:00:00 +01:00

31 lines
932 B
Plaintext

/**
* @name Self comparison
* @description Comparing a variable to itself always produces the
* same result, unless the purpose is to check for
* integer overflow or floating point NaN.
* @kind problem
* @problem.severity warning
* @precision high
* @id cpp/comparison-of-identical-expressions
* @tags readability
* maintainability
*/
import cpp
import PointlessSelfComparison
from ComparisonOperation cmp
where
pointlessSelfComparison(cmp) and
not nanTest(cmp) and
not overflowTest(cmp) and
not cmp.isFromTemplateInstantiation(_) and
not exists(MacroInvocation mi |
// cmp is in mi
mi.getAnExpandedElement() = cmp and
// and cmp was apparently not passed in as a macro parameter
cmp.getLocation().getStartLine() = mi.getLocation().getStartLine() and
cmp.getLocation().getStartColumn() = mi.getLocation().getStartColumn()
)
select cmp, "Self comparison."