mirror of
https://github.com/github/codeql.git
synced 2026-05-05 05:35:13 +02:00
CPP: Fix the issue.
This commit is contained in:
@@ -19,7 +19,11 @@ import cpp
|
||||
|
||||
predicate functionsMissingReturnStmt(Function f, ControlFlowNode blame) {
|
||||
f.fromSource() and
|
||||
not f.getType().getUnderlyingType().getUnspecifiedType() instanceof VoidType and
|
||||
exists(Type returnType |
|
||||
returnType = f.getType().getUnderlyingType().getUnspecifiedType() and
|
||||
not returnType instanceof VoidType and
|
||||
not returnType instanceof TemplateParameter
|
||||
) and
|
||||
exists(ReturnStmt s | f.getAPredecessor() = s | blame = s.getAPredecessor())}
|
||||
|
||||
/* If a function has a value-carrying return statement, but the extractor hit a snag
|
||||
@@ -32,13 +36,11 @@ predicate functionImperfectlyExtracted(Function f) {
|
||||
exists(ErrorExpr ee | ee.getEnclosingFunction() = f)
|
||||
}
|
||||
|
||||
from Stmt stmt, string msg
|
||||
from Stmt stmt, string msg, Function f, ControlFlowNode blame
|
||||
where
|
||||
exists(Function f, ControlFlowNode blame |
|
||||
functionsMissingReturnStmt(f, blame) and
|
||||
reachable(blame) and
|
||||
not functionImperfectlyExtracted(f) and
|
||||
(blame = stmt or blame.(Expr).getEnclosingStmt() = stmt) and
|
||||
msg = "Function " + f.getName() + " should return a value of type " + f.getType().getName() + " but does not return a value here"
|
||||
)
|
||||
functionsMissingReturnStmt(f, blame) and
|
||||
reachable(blame) and
|
||||
not functionImperfectlyExtracted(f) and
|
||||
(blame = stmt or blame.(Expr).getEnclosingStmt() = stmt) and
|
||||
msg = "Function " + f.getName() + " should return a value of type " + f.getType().getName() + " but does not return a value here"
|
||||
select stmt, msg
|
||||
|
||||
@@ -4,6 +4,4 @@
|
||||
| test.cpp:16:1:18:1 | { ... } | Function g2 should return a value of type MyValue but does not return a value here |
|
||||
| test.cpp:48:2:48:26 | if (...) ... | Function g7 should return a value of type MyValue but does not return a value here |
|
||||
| test.cpp:74:1:76:1 | { ... } | Function g10 should return a value of type second but does not return a value here |
|
||||
| test.cpp:80:1:82:1 | { ... } | Function g11 should return a value of type first but does not return a value here |
|
||||
| test.cpp:86:1:88:1 | { ... } | Function g12 should return a value of type second but does not return a value here |
|
||||
| test.cpp:86:1:88:1 | { ... } | Function g12 should return a value of type second but does not return a value here |
|
||||
|
||||
@@ -78,7 +78,7 @@ TypePair<void, int>::second g10()
|
||||
template<class T>
|
||||
typename TypePair<void, T>::first g11()
|
||||
{
|
||||
// GOOD (the return type amounts to void) [FALSE POSITIVE]
|
||||
// GOOD (the return type amounts to void)
|
||||
}
|
||||
|
||||
template<class T>
|
||||
|
||||
Reference in New Issue
Block a user