1 // RUN: %check_clang_tidy -format-style=LLVM -check-suffix=DEFAULT %s \ 2 // RUN: modernize-replace-disallow-copy-and-assign-macro %t 3 4 // RUN: %check_clang_tidy -format-style=LLVM -check-suffix=DIFFERENT-NAME %s \ 5 // RUN: modernize-replace-disallow-copy-and-assign-macro %t \ 6 // RUN: -config="{CheckOptions: [ \ 7 // RUN: {key: modernize-replace-disallow-copy-and-assign-macro.MacroName, \ 8 // RUN: value: MY_MACRO_NAME}]}" 9 10 // RUN: %check_clang_tidy -format-style=LLVM -check-suffix=FINALIZE %s \ 11 // RUN: modernize-replace-disallow-copy-and-assign-macro %t \ 12 // RUN: -config="{CheckOptions: [ \ 13 // RUN: {key: modernize-replace-disallow-copy-and-assign-macro.MacroName, \ 14 // RUN: value: DISALLOW_COPY_AND_ASSIGN_FINALIZE}]}" 15 16 // RUN: clang-tidy %s -checks="-*,modernize-replace-disallow-copy-and-assign-macro" \ 17 // RUN: -config="{CheckOptions: [ \ 18 // RUN: {key: modernize-replace-disallow-copy-and-assign-macro.MacroName, \ 19 // RUN: value: DISALLOW_COPY_AND_ASSIGN_MORE_AGUMENTS}]}" -- -Wno-extra-semi | count 0 20 21 // RUN: clang-tidy %s -checks="-*,modernize-replace-disallow-copy-and-assign-macro" \ 22 // RUN: -config="{CheckOptions: [ \ 23 // RUN: {key: modernize-replace-disallow-copy-and-assign-macro.MacroName, \ 24 // RUN: value: DISALLOW_COPY_AND_ASSIGN_NEEDS_PREEXPANSION}]}" -- -Wno-extra-semi | count 0 25 26 // Note: the last two tests expect no diagnostics, but FileCheck cannot handle 27 // that, hence the use of | count 0. 28 29 #define DISALLOW_COPY_AND_ASSIGN(TypeName) 30 31 class TestClass1 { 32 private: 33 DISALLOW_COPY_AND_ASSIGN(TestClass1); 34 }; 35 // CHECK-MESSAGES-DEFAULT: :[[@LINE-2]]:3: warning: prefer deleting copy constructor and assignment operator over using macro 'DISALLOW_COPY_AND_ASSIGN' [modernize-replace-disallow-copy-and-assign-macro] 36 // CHECK-FIXES-DEFAULT: {{^}} TestClass1(const TestClass1 &) = delete;{{$}} 37 // CHECK-FIXES-DEFAULT-NEXT: {{^}} const TestClass1 &operator=(const TestClass1 &) = delete;{{$}} 38 39 #define MY_MACRO_NAME(TypeName) 40 41 class TestClass2 { 42 private: 43 MY_MACRO_NAME(TestClass2); 44 }; 45 // CHECK-MESSAGES-DIFFERENT-NAME: :[[@LINE-2]]:3: warning: prefer deleting copy constructor and assignment operator over using macro 'MY_MACRO_NAME' [modernize-replace-disallow-copy-and-assign-macro] 46 // CHECK-FIXES-DIFFERENT-NAME: {{^}} TestClass2(const TestClass2 &) = delete;{{$}} 47 // CHECK-FIXES-DIFFERENT-NAME-NEXT: {{^}} const TestClass2 &operator=(const TestClass2 &) = delete;{{$}} 48 49 #define DISALLOW_COPY_AND_ASSIGN_FINALIZE(TypeName) \ 50 TypeName(const TypeName &) = delete; \ 51 const TypeName &operator=(const TypeName &) = delete; 52 53 class TestClass3 { 54 private: 55 // Notice, that the macro allows to be used without a semicolon because the 56 // macro definition already contains one above. Therefore our replacement must 57 // contain a semicolon at the end. 58 DISALLOW_COPY_AND_ASSIGN_FINALIZE(TestClass3) 59 }; 60 // CHECK-MESSAGES-FINALIZE: :[[@LINE-2]]:3: warning: prefer deleting copy constructor and assignment operator over using macro 'DISALLOW_COPY_AND_ASSIGN_FINALIZE' [modernize-replace-disallow-copy-and-assign-macro] 61 // CHECK-FIXES-FINALIZE: {{^}} TestClass3(const TestClass3 &) = delete;{{$}} 62 // CHECK-FIXES-FINALIZE-NEXT: {{^}} const TestClass3 &operator=(const TestClass3 &) = delete;{{$}} 63 64 #define DISALLOW_COPY_AND_ASSIGN_MORE_AGUMENTS(A, B) 65 66 class TestClass4 { 67 private: 68 DISALLOW_COPY_AND_ASSIGN_MORE_AGUMENTS(TestClass4, TestClass4); 69 }; 70 // CHECK-MESSAGES-MORE-ARGUMENTS-NOT: warning: prefer deleting copy constructor and assignment operator over using macro 'DISALLOW_COPY_AND_ASSIGN_MORE_AGUMENTS' 71 72 #define DISALLOW_COPY_AND_ASSIGN_NEEDS_PREEXPANSION(A) 73 #define TESTCLASS TestClass5 74 75 class TestClass5 { 76 private: 77 DISALLOW_COPY_AND_ASSIGN_NEEDS_PREEXPANSION(TESTCLASS); 78 }; 79 // CHECK-MESSAGES-MORE-ARGUMENTS-NOT: warning: prefer deleting copy constructor and assignment operator over using macro 'DISALLOW_COPY_AND_ASSIGN_NEEDS_PREEXPANSION' 80