Skip to content

Commit 8f05c17

Browse files
committed
[alpha.webkit.UncheckedCallArgsChecker] Don't emit a warning for passing a temporary object as an argument. (llvm#155033)
Since a temporary object lives until the end of the statement, it's safe to pass such an object as a function argument without explicitly creating a CheckedRef/CheckedPtr in stack.
1 parent a7930a0 commit 8f05c17

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,8 @@ bool isASafeCallArg(const Expr *E) {
208208
return true;
209209
}
210210
}
211+
if (isa<CXXTemporaryObjectExpr>(E))
212+
return true; // A temporary lives until the end of this statement.
211213
if (isConstOwnerPtrMemberExpr(E))
212214
return true;
213215

clang/test/Analysis/Checkers/WebKit/unchecked-call-arg.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,8 @@ void foo() {
3232
provide()->doWork();
3333
// expected-warning@-1{{Call argument for 'this' parameter is unchecked and unsafe}}
3434
}
35+
36+
void doWorkWithObject(const CheckedObject&);
37+
void bar() {
38+
doWorkWithObject(CheckedObject());
39+
}

0 commit comments

Comments
 (0)