1 // RUN: %clang_analyze_cc1 -analyzer-checker=alpha.webkit.UncountedLocalVarsChecker -verify %s
3 #include "mock-types.h"
8 // FIXME: later on we might warn on uninitialized vars too
11 void bar(RefCountable
*) {}
12 } // namespace raw_ptr
16 RefCountable automatic
;
17 RefCountable
&bar
= automatic
;
18 // expected-warning@-1{{Local variable 'bar' is uncounted and unsafe [alpha.webkit.UncountedLocalVarsChecker]}}
21 void bar_ref(RefCountable
&) {}
22 } // namespace reference
24 namespace guardian_scopes
{
26 RefPtr
<RefCountable
> foo
;
27 { RefCountable
*bar
= foo
.get(); }
31 RefPtr
<RefCountable
> foo
;
32 // missing embedded scope here
33 RefCountable
*bar
= foo
.get();
34 // expected-warning@-1{{Local variable 'bar' is uncounted and unsafe [alpha.webkit.UncountedLocalVarsChecker]}}
38 RefPtr
<RefCountable
> foo
;
40 { RefCountable
*bar
= foo
.get(); }
46 RefPtr
<RefCountable
> foo
;
47 { RefCountable
*bar
= foo
.get(); }
50 } // namespace guardian_scopes
52 namespace auto_keyword
{
54 RefCountable
*provide_ref_ctnbl() { return nullptr; }
57 RefCountable
*bar
= provide_ref_ctnbl();
58 // expected-warning@-1{{Local variable 'bar' is uncounted and unsafe [alpha.webkit.UncountedLocalVarsChecker]}}
59 auto *baz
= provide_ref_ctnbl();
60 // expected-warning@-1{{Local variable 'baz' is uncounted and unsafe [alpha.webkit.UncountedLocalVarsChecker]}}
61 auto *baz2
= this->provide_ref_ctnbl();
62 // expected-warning@-1{{Local variable 'baz2' is uncounted and unsafe [alpha.webkit.UncountedLocalVarsChecker]}}
65 } // namespace auto_keyword
67 namespace guardian_casts
{
69 RefPtr
<RefCountable
> foo
;
70 { RefCountable
*bar
= downcast
<RefCountable
>(foo
.get()); }
74 RefPtr
<RefCountable
> foo
;
77 static_cast<RefCountable
*>(downcast
<RefCountable
>(foo
.get()));
80 } // namespace guardian_casts
82 namespace guardian_ref_conversion_operator
{
85 { RefCountable
&rr
= rc
; }
87 } // namespace guardian_ref_conversion_operator
89 namespace ignore_for_if
{
90 RefCountable
*provide_ref_ctnbl() { return nullptr; }
94 if (RefCountable
*a
= provide_ref_ctnbl()) { }
95 for (RefCountable
*a
= provide_ref_ctnbl(); a
!= nullptr;) { }
96 RefCountable
*array
[1];
97 for (RefCountable
*a
: array
) { }
99 } // namespace ignore_for_if