1 // RUN: %check_clang_tidy %s bugprone-unused-raii %t
2
3 struct Foo {
4 Foo();
5 Foo(int);
6 Foo(int, int);
7 ~Foo();
8 };
9
10 struct Bar {
11 Bar();
12 };
13
14 struct FooBar {
15 FooBar();
16 Foo f;
17 };
18
19 template <typename T>
qux()20 void qux() {
21 T(42);
22 }
23
24 template <typename T>
25 struct TFoo {
26 TFoo(T);
27 ~TFoo();
28 };
29
30 Foo f();
31
32 struct Ctor {
33 Ctor(int);
CtorCtor34 Ctor() {
35 Ctor(0); // TODO: warn here.
36 }
37 };
38
test()39 void test() {
40 Foo(42);
41 // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: object destroyed immediately after creation; did you mean to name the object?
42 // CHECK-FIXES: Foo give_me_a_name(42);
43 Foo(23, 42);
44 // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: object destroyed immediately after creation; did you mean to name the object?
45 // CHECK-FIXES: Foo give_me_a_name(23, 42);
46 Foo();
47 // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: object destroyed immediately after creation; did you mean to name the object?
48 // CHECK-FIXES: Foo give_me_a_name;
49 TFoo<int>(23);
50 // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: object destroyed immediately after creation; did you mean to name the object?
51 // CHECK-FIXES: TFoo<int> give_me_a_name(23);
52
53 FooBar();
54 // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: object destroyed immediately after creation; did you mean to name the object?
55 // CHECK-FIXES: FooBar give_me_a_name;
56
57 Bar();
58 f();
59 qux<Foo>();
60
61 #define M Foo();
62 M
63
64 {
65 Foo();
66 }
67 Foo();
68 }
69