brintos

brintos / llvm-project-archived public Read only

0
0
Text · 9.1 KiB · 0cdf6a7 Raw
178 lines · cpp
1// RUN: %check_clang_tidy %s readability-operators-representation %t -- -config="{CheckOptions: {\2// RUN: readability-operators-representation.BinaryOperators: 'and;and_eq;bitand;bitor;compl;not;not_eq;or;or_eq;xor;xor_eq', \3// RUN: readability-operators-representation.OverloadedOperators: 'and;and_eq;bitand;bitor;compl;not;not_eq;or;or_eq;xor;xor_eq'}}" --4 5void testAllTokensToAlternative(int a, int b) {6  int value = 0;7 8  value = a||b;9  // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: '||' is a traditional token spelling, consider using an alternative token 'or' for consistency [readability-operators-representation]10  // CHECK-FIXES: value = a or b;11 12  value = a&&b;13  // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: '&&' is a traditional token spelling, consider using an alternative token 'and' for consistency [readability-operators-representation]14  // CHECK-FIXES: value = a and b;15 16  value = a | b;17  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: '|' is a traditional token spelling, consider using an alternative token 'bitor' for consistency [readability-operators-representation]18  // CHECK-FIXES: value = a bitor b;19 20  value = a & b;21  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: '&' is a traditional token spelling, consider using an alternative token 'bitand' for consistency [readability-operators-representation]22  // CHECK-FIXES: value = a bitand b;23 24  value = !a;25  // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: '!' is a traditional token spelling, consider using an alternative token 'not' for consistency [readability-operators-representation]26  // CHECK-FIXES: value = not a;27 28  value = a^b;29  // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: '^' is a traditional token spelling, consider using an alternative token 'xor' for consistency [readability-operators-representation]30  // CHECK-FIXES: value = a xor b;31 32  value = ~b;33  // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: '~' is a traditional token spelling, consider using an alternative token 'compl' for consistency [readability-operators-representation]34  // CHECK-FIXES: value = compl b;35 36  value &= b;37  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: '&=' is a traditional token spelling, consider using an alternative token 'and_eq' for consistency [readability-operators-representation]38  // CHECK-FIXES: value and_eq b;39 40  value |= b;41  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: '|=' is a traditional token spelling, consider using an alternative token 'or_eq' for consistency [readability-operators-representation]42  // CHECK-FIXES: value or_eq b;43 44  value = a != b;45  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: '!=' is a traditional token spelling, consider using an alternative token 'not_eq' for consistency [readability-operators-representation]46  // CHECK-FIXES: value = a not_eq b;47 48  value ^= a;49  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: '^=' is a traditional token spelling, consider using an alternative token 'xor_eq' for consistency [readability-operators-representation]50  // CHECK-FIXES: value xor_eq a;51}52 53struct Class {54  bool operator!() const;55  Class operator~() const;56  bool operator&&(const Class&) const;57  Class operator&(const Class&) const;58  bool operator||(const Class&) const;59  Class operator|(const Class&) const;60  Class operator^(const Class&) const;61  Class& operator&=(const Class&) const;62  Class& operator|=(const Class&) const;63  Class& operator^=(const Class&) const;64  bool operator!=(const Class&) const;65};66 67void testAllTokensToAlternative(Class a, Class b) {68  int value = 0;69  Class clval;70 71  value = a||b;72  // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: '||' is a traditional token spelling, consider using an alternative token 'or' for consistency [readability-operators-representation]73  // CHECK-FIXES: value = a or b;74 75  value = a&&b;76  // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: '&&' is a traditional token spelling, consider using an alternative token 'and' for consistency [readability-operators-representation]77  // CHECK-FIXES: value = a and b;78 79  clval = a | b;80  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: '|' is a traditional token spelling, consider using an alternative token 'bitor' for consistency [readability-operators-representation]81  // CHECK-FIXES: clval = a bitor b;82 83  clval = a & b;84  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: '&' is a traditional token spelling, consider using an alternative token 'bitand' for consistency [readability-operators-representation]85  // CHECK-FIXES: clval = a bitand b;86 87  value = !a;88  // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: '!' is a traditional token spelling, consider using an alternative token 'not' for consistency [readability-operators-representation]89  // CHECK-FIXES: value = not a;90 91  clval = a^b;92  // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: '^' is a traditional token spelling, consider using an alternative token 'xor' for consistency [readability-operators-representation]93  // CHECK-FIXES: clval = a xor b;94 95  clval = ~b;96  // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: '~' is a traditional token spelling, consider using an alternative token 'compl' for consistency [readability-operators-representation]97  // CHECK-FIXES: clval = compl b;98 99  clval &= b;100  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: '&=' is a traditional token spelling, consider using an alternative token 'and_eq' for consistency [readability-operators-representation]101  // CHECK-FIXES: clval and_eq b;102 103  clval |= b;104  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: '|=' is a traditional token spelling, consider using an alternative token 'or_eq' for consistency [readability-operators-representation]105  // CHECK-FIXES: clval or_eq b;106 107  value = a != b;108  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: '!=' is a traditional token spelling, consider using an alternative token 'not_eq' for consistency [readability-operators-representation]109  // CHECK-FIXES: value = a not_eq b;110 111  clval ^= a;112  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: '^=' is a traditional token spelling, consider using an alternative token 'xor_eq' for consistency [readability-operators-representation]113  // CHECK-FIXES: clval xor_eq a;114}115 116struct ClassO {};117 118ClassO& operator&=(ClassO&, const ClassO&);119ClassO& operator|=(ClassO&, const ClassO&);120ClassO& operator^=(ClassO&, const ClassO&);121bool operator!=(const ClassO&, const ClassO&);122bool operator&&(const ClassO&, const ClassO&);123bool operator||(const ClassO&, const ClassO&);124bool operator!(const ClassO&);125ClassO operator&(const ClassO&, const ClassO&);126ClassO operator|(const ClassO&, const ClassO&);127ClassO operator^(const ClassO&, const ClassO&);128ClassO operator~(const ClassO&);129 130void testAllTokensToAlternative(ClassO a, ClassO b) {131  int value = 0;132  ClassO clval;133 134  value = a||b;135  // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: '||' is a traditional token spelling, consider using an alternative token 'or' for consistency [readability-operators-representation]136  // CHECK-FIXES: value = a or b;137 138  value = a&&b;139  // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: '&&' is a traditional token spelling, consider using an alternative token 'and' for consistency [readability-operators-representation]140  // CHECK-FIXES: value = a and b;141 142  clval = a | b;143  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: '|' is a traditional token spelling, consider using an alternative token 'bitor' for consistency [readability-operators-representation]144  // CHECK-FIXES: clval = a bitor b;145 146  clval = a & b;147  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: '&' is a traditional token spelling, consider using an alternative token 'bitand' for consistency [readability-operators-representation]148  // CHECK-FIXES: clval = a bitand b;149 150  value = !a;151  // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: '!' is a traditional token spelling, consider using an alternative token 'not' for consistency [readability-operators-representation]152  // CHECK-FIXES: value = not a;153 154  clval = a^b;155  // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: '^' is a traditional token spelling, consider using an alternative token 'xor' for consistency [readability-operators-representation]156  // CHECK-FIXES: clval = a xor b;157 158  clval = ~b;159  // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: '~' is a traditional token spelling, consider using an alternative token 'compl' for consistency [readability-operators-representation]160  // CHECK-FIXES: clval = compl b;161 162  clval &= b;163  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: '&=' is a traditional token spelling, consider using an alternative token 'and_eq' for consistency [readability-operators-representation]164  // CHECK-FIXES: clval and_eq b;165 166  clval |= b;167  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: '|=' is a traditional token spelling, consider using an alternative token 'or_eq' for consistency [readability-operators-representation]168  // CHECK-FIXES: clval or_eq b;169 170  value = a != b;171  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: '!=' is a traditional token spelling, consider using an alternative token 'not_eq' for consistency [readability-operators-representation]172  // CHECK-FIXES: value = a not_eq b;173 174  clval ^= a;175  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: '^=' is a traditional token spelling, consider using an alternative token 'xor_eq' for consistency [readability-operators-representation]176  // CHECK-FIXES: clval xor_eq a;177}178