1 | // RUN: %check_clang_tidy %s bugprone-undelegated-constructor %t |
2 | |
3 | struct Ctor; |
4 | Ctor foo(); |
5 | |
6 | struct Ctor { |
7 | Ctor(); |
8 | Ctor(int); |
9 | Ctor(int, int); |
10 | Ctor(Ctor *i) { |
11 | Ctor(); |
12 | // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: did you intend to call a delegated constructor? A temporary object is created here instead [bugprone-undelegated-constructor] |
13 | Ctor(0); |
14 | // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: did you intend to call a delegated constructor? |
15 | Ctor(1, 2); |
16 | // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: did you intend to call a delegated constructor? |
17 | foo(); |
18 | } |
19 | }; |
20 | |
21 | Ctor::Ctor() { |
22 | Ctor(1); |
23 | // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: did you intend to call a delegated constructor? |
24 | } |
25 | |
26 | Ctor::Ctor(int i) : Ctor(i, 1) {} // properly delegated. |
27 | |
28 | struct Dtor { |
29 | Dtor(); |
30 | Dtor(int); |
31 | Dtor(int, int); |
32 | Dtor(Ctor *i) { |
33 | Dtor(); |
34 | // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: did you intend to call a delegated constructor? |
35 | Dtor(0); |
36 | // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: did you intend to call a delegated constructor? |
37 | Dtor(1, 2); |
38 | // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: did you intend to call a delegated constructor? |
39 | } |
40 | ~Dtor(); |
41 | }; |
42 | |
43 | struct Base {}; |
44 | struct Derived : public Base { |
45 | Derived() { Base(); } |
46 | // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: did you intend to call a delegated constructor? |
47 | }; |
48 | |
49 | template <typename T> |
50 | struct TDerived : public Base { |
51 | TDerived() { Base(); } |
52 | }; |
53 | |
54 | TDerived<int> t; |
55 | |