mirror of
https://github.com/github/codeql.git
synced 2026-04-29 02:35:15 +02:00
C++: Fix AV Rule 85
We have to be careful to avoid giving alerts to functions that might be correctly defined, but we can't see the definition as it wasn't instantiated.
This commit is contained in:
@@ -28,14 +28,34 @@ predicate implementedAsNegationOf(Operator op1, Operator op2) {
|
||||
c.getTarget() = op2)
|
||||
}
|
||||
|
||||
predicate classIsCheckableFor(Class c, string op) {
|
||||
oppositeOperators(op, _) and
|
||||
if exists(Class templ | c.isConstructedFrom(templ))
|
||||
then // If we are an instantiation, then we can't check `op` if the
|
||||
// template has it but we don't (because that member wasn't
|
||||
// instantiated)
|
||||
exists(Class templ | c.isConstructedFrom(templ) and
|
||||
(templ.getAMember().hasName(op) implies
|
||||
exists(Function f | f = c.getAMember() and
|
||||
f.hasName(op) and
|
||||
f.isDefined())))
|
||||
else any()
|
||||
}
|
||||
|
||||
from Class c, string op, string opp, Operator rator
|
||||
where c.fromSource() and
|
||||
not c instanceof TemplateClass and
|
||||
oppositeOperators(op, opp) and
|
||||
classIsCheckableFor(c, op) and
|
||||
classIsCheckableFor(c, opp) and
|
||||
rator = c.getAMember() and
|
||||
rator.hasName(op) and
|
||||
not exists(Operator oprator | oprator = c.getAMember() and
|
||||
oprator.hasName(opp) and
|
||||
( implementedAsNegationOf(rator, oprator)
|
||||
or implementedAsNegationOf(oprator, rator)))
|
||||
forex(Operator aRator |
|
||||
aRator = c.getAMember() and aRator.hasName(op) |
|
||||
not exists(Operator oprator |
|
||||
oprator = c.getAMember() and
|
||||
oprator.hasName(opp) and
|
||||
( implementedAsNegationOf(aRator, oprator)
|
||||
or implementedAsNegationOf(oprator, aRator))))
|
||||
select c, "When two operators are opposites, both should be defined and one should be defined in terms of the other. Operator " + op +
|
||||
" is declared on line " + rator.getLocation().getStartLine().toString() + ", but it is not defined in terms of its opposite operator " + opp + "."
|
||||
|
||||
Reference in New Issue
Block a user