mirror of
https://github.com/github/codeql.git
synced 2026-07-21 03:08:25 +02:00
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.
31 lines
932 B
Plaintext
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."
|