1 // RUN: %check_clang_tidy %s bugprone-unhandled-self-assignment %t -- \
2 // RUN:   -config="{CheckOptions: \
3 // RUN:             [{key: bugprone-unhandled-self-assignment.WarnOnlyIfThisHasSuspiciousField, \
4 // RUN:               value: false}]}"
5 
6 // Classes with pointer field are still caught.
7 class PtrField {
8 public:
operator =(const PtrField & object)9   PtrField &operator=(const PtrField &object) {
10     // CHECK-MESSAGES: [[@LINE-1]]:13: warning: operator=() does not handle self-assignment properly [bugprone-unhandled-self-assignment]
11     return *this;
12   }
13 
14 private:
15   int *p;
16 };
17 
18 // With the option, check catches classes with trivial fields.
19 class TrivialFields {
20 public:
operator =(const TrivialFields & object)21   TrivialFields &operator=(const TrivialFields &object) {
22     // CHECK-MESSAGES: [[@LINE-1]]:18: warning: operator=() does not handle self-assignment properly [bugprone-unhandled-self-assignment]
23     return *this;
24   }
25 
26 private:
27   int m;
28   float f;
29   double d;
30   bool b;
31 };
32 
33 // The check warns also when there is no field at all.
34 // In this case, user-defined copy assignment operator is useless anyway.
35 class ClassWithoutFields {
36 public:
operator =(const ClassWithoutFields & object)37   ClassWithoutFields &operator=(const ClassWithoutFields &object) {
38     // CHECK-MESSAGES: [[@LINE-1]]:23: warning: operator=() does not handle self-assignment properly [bugprone-unhandled-self-assignment]
39     return *this;
40   }
41 };
42