1// RUN: %check_clang_tidy %s bugprone-undelegated-constructor %t
2
3struct Ctor;
4Ctor foo();
5
6struct 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
21Ctor::Ctor() {
22 Ctor(1);
23// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: did you intend to call a delegated constructor?
24}
25
26Ctor::Ctor(int i) : Ctor(i, 1) {} // properly delegated.
27
28struct 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
43struct Base {};
44struct Derived : public Base {
45 Derived() { Base(); }
46// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: did you intend to call a delegated constructor?
47};
48
49template <typename T>
50struct TDerived : public Base {
51 TDerived() { Base(); }
52};
53
54TDerived<int> t;
55

source code of clang-tools-extra/test/clang-tidy/checkers/bugprone/undelegated-constructor.cpp