[LLVM][NVPTX] Add support for griddepcontrol instruction (#123511)
[llvm-project.git] / clang / test / Analysis / Checkers / WebKit / call-args-checked-const-member.cpp
blobf7095606c77a4c9fae75bbd6b671262c67627940
1 // RUN: %clang_analyze_cc1 -analyzer-checker=alpha.webkit.UncheckedCallArgsChecker -verify %s
3 #include "mock-types.h"
5 namespace call_args_const_checkedptr_member {
7 class Foo {
8 public:
9 Foo();
10 void bar();
12 private:
13 const CheckedPtr<CheckedObj> m_obj1;
14 CheckedPtr<CheckedObj> m_obj2;
17 void Foo::bar() {
18 m_obj1->method();
19 m_obj2->method();
20 // expected-warning@-1{{Call argument for 'this' parameter is unchecked and unsafe}}
23 } // namespace call_args_const_checkedptr_member
25 namespace call_args_const_checkedref_member {
27 class Foo {
28 public:
29 Foo();
30 void bar();
32 private:
33 const CheckedRef<CheckedObj> m_obj1;
34 CheckedRef<CheckedObj> m_obj2;
37 void Foo::bar() {
38 m_obj1->method();
39 m_obj2->method();
40 // expected-warning@-1{{Call argument for 'this' parameter is unchecked and unsafe}}
43 } // namespace call_args_const_checkedref_member
45 namespace call_args_const_unique_ptr {
47 class Foo {
48 public:
49 Foo();
50 void bar();
52 CheckedObj& ensureObj3() {
53 if (!m_obj3)
54 const_cast<std::unique_ptr<CheckedObj>&>(m_obj3) = new CheckedObj;
55 return *m_obj3;
58 CheckedObj& badEnsureObj4() {
59 if (!m_obj4)
60 const_cast<std::unique_ptr<CheckedObj>&>(m_obj4) = new CheckedObj;
61 if (auto* next = m_obj4->next())
62 return *next;
63 return *m_obj4;
66 CheckedObj* ensureObj5() {
67 if (!m_obj5)
68 const_cast<std::unique_ptr<CheckedObj>&>(m_obj5) = new CheckedObj;
69 if (m_obj5->next())
70 return nullptr;
71 return m_obj5.get();
74 private:
75 const std::unique_ptr<CheckedObj> m_obj1;
76 std::unique_ptr<CheckedObj> m_obj2;
77 const std::unique_ptr<CheckedObj> m_obj3;
78 const std::unique_ptr<CheckedObj> m_obj4;
79 const std::unique_ptr<CheckedObj> m_obj5;
82 void Foo::bar() {
83 m_obj1->method();
84 m_obj2->method();
85 // expected-warning@-1{{Call argument for 'this' parameter is unchecked and unsafe}}
86 ensureObj3().method();
87 badEnsureObj4().method();
88 // expected-warning@-1{{Call argument for 'this' parameter is unchecked and unsafe}}
89 ensureObj5()->method();
92 } // namespace call_args_const_unique_ptr