Skip to content

Commit 44bdf98

Browse files
author
Robert Marsh
committed
C++: simplify and explain getExplicitlyConverted
1 parent 65cc988 commit 44bdf98

File tree

1 file changed

+8
-11
lines changed
  • cpp/ql/src/semmle/code/cpp/exprs

1 file changed

+8
-11
lines changed

cpp/ql/src/semmle/code/cpp/exprs/Expr.qll

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -453,19 +453,16 @@ class Expr extends StmtParent, @expr {
453453
* cast from B to C. Only (1) and (2) would be included.
454454
*/
455455
Expr getExplicitlyConverted() {
456-
if this.hasConversion()
456+
// For performance, we avoid a full transitive closure over `getConversion`.
457+
// Since there can be several implicit conversions before and after an
458+
// explicit conversion, use `getImplicitlyConverted` to step over them
459+
// cheaply. Then, if there is an explicit conversion following the implict
460+
// conversion sequence, recurse to handle multiple explicit conversions.
461+
if this.getImplicitlyConverted().hasExplicitConversion()
457462
then
458-
if this.hasExplicitConversion()
459-
then
460-
result = this.getConversion().getExplicitlyConverted()
463+
result = this.getImplicitlyConverted().getConversion().getExplicitlyConverted()
461464
else
462-
if this.getImplicitlyConverted().hasExplicitConversion()
463-
then
464-
result = this.getImplicitlyConverted().getConversion().getExplicitlyConverted()
465-
else
466-
result = this
467-
else
468-
result = this
465+
result = this
469466
}
470467

471468
/**

0 commit comments

Comments
 (0)