Skip to content

Allow default arguments to be evaluated like other arguments. #80956

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 2 commits into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ class UncountedCallArgsChecker

const auto *Arg = CE->getArg(ArgIdx);

if (auto *defaultArg = dyn_cast<CXXDefaultArgExpr>(Arg))
Arg = defaultArg->getExpr();

std::pair<const clang::Expr *, bool> ArgOrigin =
tryToFindPtrOrigin(Arg, true);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// RUN: %clang_analyze_cc1 -analyzer-checker=alpha.webkit.UncountedCallArgsChecker -verify %s

template <typename T>
class RefPtr {
public:
RefPtr(T* ptr)
: m_ptr(ptr)
{
if (m_ptr)
m_ptr->ref();
}

~RefPtr()
{
if (m_ptr)
m_ptr->deref();
}

T* get() { return m_ptr; }

private:
T* m_ptr;
};

class Obj {
public:
static Obj* get();
static RefPtr<Obj> create();
void ref() const;
void deref() const;
};

void someFunction(Obj*, Obj* = nullptr);
void otherFunction(Obj*, Obj* = Obj::get());
// expected-warning@-1{{Call argument is uncounted and unsafe [alpha.webkit.UncountedCallArgsChecker]}}
void anotherFunction(Obj*, Obj* = Obj::create().get());

void otherFunction() {
someFunction(nullptr);
someFunction(Obj::get());
// expected-warning@-1{{Call argument is uncounted and unsafe [alpha.webkit.UncountedCallArgsChecker]}}
someFunction(Obj::create().get());
otherFunction(nullptr);
anotherFunction(nullptr);
}