[RISCV] Simplify usage of SplatPat_simm5_plus1. NFC (#125340)
[llvm-project.git] / clang / test / Analysis / Checkers / WebKit / call-args-counted-const-member.cpp
blob215238a7fcf0712ae478945247389984ea5ed0ae
1 // RUN: %clang_analyze_cc1 -analyzer-checker=alpha.webkit.UncountedCallArgsChecker -verify %s
3 #include "mock-types.h"
5 namespace std {
8 namespace call_args_const_refptr_member {
10 class Foo {
11 public:
12 Foo();
13 void bar();
15 private:
16 const RefPtr<RefCountable> m_obj1;
17 RefPtr<RefCountable> m_obj2;
20 void Foo::bar() {
21 m_obj1->method();
22 m_obj2->method();
23 // expected-warning@-1{{Call argument for 'this' parameter is uncounted and unsafe}}
26 } // namespace call_args_const_refptr_member
28 namespace call_args_const_ref_member {
30 class Foo {
31 public:
32 Foo();
33 void bar();
35 private:
36 const Ref<RefCountable> m_obj1;
37 Ref<RefCountable> m_obj2;
40 void Foo::bar() {
41 m_obj1->method();
42 m_obj2->method();
43 // expected-warning@-1{{Call argument for 'this' parameter is uncounted and unsafe}}
46 } // namespace call_args_const_ref_member
48 namespace call_args_const_unique_ptr {
50 class Foo {
51 public:
52 Foo();
53 void bar();
55 RefCountable& ensureObj3() {
56 if (!m_obj3)
57 const_cast<std::unique_ptr<RefCountable>&>(m_obj3) = RefCountable::makeUnique();
58 return *m_obj3;
61 RefCountable& badEnsureObj4() {
62 if (!m_obj4)
63 const_cast<std::unique_ptr<RefCountable>&>(m_obj4) = RefCountable::makeUnique();
64 if (auto* next = m_obj4->next())
65 return *next;
66 return *m_obj4;
69 RefCountable* ensureObj5() {
70 if (!m_obj5)
71 const_cast<std::unique_ptr<RefCountable>&>(m_obj5) = RefCountable::makeUnique();
72 if (m_obj5->next())
73 return nullptr;
74 return m_obj5.get();
77 private:
78 const std::unique_ptr<RefCountable> m_obj1;
79 std::unique_ptr<RefCountable> m_obj2;
80 const std::unique_ptr<RefCountable> m_obj3;
81 const std::unique_ptr<RefCountable> m_obj4;
82 const std::unique_ptr<RefCountable> m_obj5;
85 void Foo::bar() {
86 m_obj1->method();
87 m_obj2->method();
88 // expected-warning@-1{{Call argument for 'this' parameter is uncounted and unsafe}}
89 ensureObj3().method();
90 badEnsureObj4().method();
91 // expected-warning@-1{{Call argument for 'this' parameter is uncounted and unsafe}}
92 ensureObj5()->method();
95 } // namespace call_args_const_unique_ptr
97 namespace call_args_const_unique_ref {
99 class Foo {
100 public:
101 Foo();
102 void bar();
104 private:
105 const UniqueRef<RefCountable> m_obj1;
106 UniqueRef<RefCountable> m_obj2;
109 void Foo::bar() {
110 m_obj1->method();
111 m_obj2->method();
112 // expected-warning@-1{{Call argument for 'this' parameter is uncounted and unsafe}}
115 } // namespace call_args_const_unique_ref