189a1d03eSRichard // RUN: %check_clang_tidy %s bugprone-unhandled-self-assignment %t -- \ 289a1d03eSRichard // RUN: -config="{CheckOptions: \ 3*e8a3ddafSNathan James // RUN: {bugprone-unhandled-self-assignment.WarnOnlyIfThisHasSuspiciousField: false}}" 489a1d03eSRichard 589a1d03eSRichard // Classes with pointer field are still caught. 689a1d03eSRichard class PtrField { 789a1d03eSRichard public: operator =(const PtrField & object)889a1d03eSRichard PtrField &operator=(const PtrField &object) { 989a1d03eSRichard // CHECK-MESSAGES: [[@LINE-1]]:13: warning: operator=() does not handle self-assignment properly [bugprone-unhandled-self-assignment] 1089a1d03eSRichard return *this; 1189a1d03eSRichard } 1289a1d03eSRichard 1389a1d03eSRichard private: 1489a1d03eSRichard int *p; 1589a1d03eSRichard }; 1689a1d03eSRichard 1789a1d03eSRichard // With the option, check catches classes with trivial fields. 1889a1d03eSRichard class TrivialFields { 1989a1d03eSRichard public: operator =(const TrivialFields & object)2089a1d03eSRichard TrivialFields &operator=(const TrivialFields &object) { 2189a1d03eSRichard // CHECK-MESSAGES: [[@LINE-1]]:18: warning: operator=() does not handle self-assignment properly [bugprone-unhandled-self-assignment] 2289a1d03eSRichard return *this; 2389a1d03eSRichard } 2489a1d03eSRichard 2589a1d03eSRichard private: 2689a1d03eSRichard int m; 2789a1d03eSRichard float f; 2889a1d03eSRichard double d; 2989a1d03eSRichard bool b; 3089a1d03eSRichard }; 3189a1d03eSRichard 3289a1d03eSRichard // The check warns also when there is no field at all. 3389a1d03eSRichard // In this case, user-defined copy assignment operator is useless anyway. 3489a1d03eSRichard class ClassWithoutFields { 3589a1d03eSRichard public: operator =(const ClassWithoutFields & object)3689a1d03eSRichard ClassWithoutFields &operator=(const ClassWithoutFields &object) { 3789a1d03eSRichard // CHECK-MESSAGES: [[@LINE-1]]:23: warning: operator=() does not handle self-assignment properly [bugprone-unhandled-self-assignment] 3889a1d03eSRichard return *this; 3989a1d03eSRichard } 4089a1d03eSRichard }; 41