Skip to content

Commit 6a48ad0

Browse files
committed
C++: Implement Expr::mayBeFromImplicitlyDeclaredFunction
1 parent 853128c commit 6a48ad0

File tree

11 files changed

+37
-1
lines changed

11 files changed

+37
-1
lines changed

cpp/ql/lib/semmle/code/cpp/exprs/Call.qll

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,11 @@ class FunctionCall extends Call, @funbindexpr {
300300
this.isVirtual() or
301301
this.getTarget().getAnAttribute().getName() = "weak"
302302
}
303+
304+
override predicate mayBeFromImplicitlyDeclaredFunction() {
305+
this.getType() instanceof IntType and
306+
this.getTarget().getADeclarationEntry().isImplicit()
307+
}
303308
}
304309

305310
/** A _user-defined_ unary `operator*` function. */

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,9 @@ class Expr extends StmtParent, @expr {
534534

535535
/** Gets the function containing this control-flow node. */
536536
override Function getControlFlowScope() { result = this.getEnclosingFunction() }
537+
538+
/** Holds if this expression could be the return value of an implicitly declared function. */
539+
predicate mayBeFromImplicitlyDeclaredFunction() { none() }
537540
}
538541

539542
/**

cpp/ql/src/Likely Bugs/Format/WrongTypeFormatArguments.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ where
171171
not arg.isAffectedByMacro() and
172172
not arg.isFromUninstantiatedTemplate(_) and
173173
not actual.getUnspecifiedType() instanceof ErroneousType and
174-
not arg.(Call).getTarget().getADeclarationEntry().isImplicit()
174+
not arg.mayBeFromImplicitlyDeclaredFunction()
175175
select arg,
176176
"This format specifier for type '" + expected.getName() + "' does not match the argument type '" +
177177
actual.getUnspecifiedType().getName() + "'."
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
| file://:0:0:0:0 | <error expr> |
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import cpp
2+
3+
from Expr e
4+
where e.getType() instanceof ErroneousType
5+
select e
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
| file://:0:0:0:0 | There was an error during this compilation |
2+
| implicit.cpp:5:5:5:5 | identifier 'g' is undefined |
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import cpp
2+
3+
from Diagnostic d
4+
select d
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
void f() {
2+
f();
3+
g();
4+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// semmle-extractor-options: --expect_errors
2+
3+
void f() {
4+
f();
5+
g();
6+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
| implicit.c:3:5:3:5 | call to g |

0 commit comments

Comments
 (0)