Skip to content

[WebKit Checkers] Allow operator T&() in a const member function #126470

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 11, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
Original file line number Diff line number Diff line change
@@ -154,10 +154,10 @@ bool isConstOwnerPtrMemberExpr(const clang::Expr *E) {
if (auto *MCE = dyn_cast<CXXMemberCallExpr>(E)) {
if (auto *Callee = MCE->getDirectCallee()) {
auto Name = safeGetName(Callee);
if (Name == "get" || Name == "ptr") {
auto *ThisArg = MCE->getImplicitObjectArgument();
E = ThisArg;
}
if (Name == "get" || Name == "ptr")
E = MCE->getImplicitObjectArgument();
if (auto *CD = dyn_cast<CXXConversionDecl>(Callee))
E = MCE->getImplicitObjectArgument();
}
} else if (auto *OCE = dyn_cast<CXXOperatorCallExpr>(E)) {
if (OCE->getOperator() == OO_Star && OCE->getNumArgs() == 1)
Original file line number Diff line number Diff line change
@@ -31,6 +31,7 @@ class Foo {
public:
Foo();
void bar();
RefCountable& obj1() const { return m_obj1; }

private:
const Ref<RefCountable> m_obj1;
@@ -41,6 +42,7 @@ void Foo::bar() {
m_obj1->method();
m_obj2->method();
// expected-warning@-1{{Call argument for 'this' parameter is uncounted and unsafe}}
obj1().method();
}

} // namespace call_args_const_ref_member
@@ -100,6 +102,7 @@ class Foo {
public:
Foo();
void bar();
RefCountable& obj1() { return m_obj1; }

private:
const UniqueRef<RefCountable> m_obj1;
@@ -110,6 +113,7 @@ void Foo::bar() {
m_obj1->method();
m_obj2->method();
// expected-warning@-1{{Call argument for 'this' parameter is uncounted and unsafe}}
obj1().method();
}

} // namespace call_args_const_unique_ref
1 change: 1 addition & 0 deletions clang/test/Analysis/Checkers/WebKit/mock-types.h
Original file line number Diff line number Diff line change
@@ -289,6 +289,7 @@ class UniqueRef {
u.t = nullptr;
}
T &get() const { return *t; }
operator T&() const { return *t; }
T *operator->() const { return t; }
UniqueRef &operator=(T &) { return *this; }
};