diff options
Diffstat (limited to 'clang-tools-extra/test')
| -rw-r--r-- | clang-tools-extra/test/clang-tidy/checkers/readability-magic-numbers-bitfields.cpp | 22 | ||||
| -rw-r--r-- | clang-tools-extra/test/clang-tidy/checkers/readability-magic-numbers.cpp | 18 |
2 files changed, 40 insertions, 0 deletions
diff --git a/clang-tools-extra/test/clang-tidy/checkers/readability-magic-numbers-bitfields.cpp b/clang-tools-extra/test/clang-tidy/checkers/readability-magic-numbers-bitfields.cpp new file mode 100644 index 00000000000..3c1fef939c6 --- /dev/null +++ b/clang-tools-extra/test/clang-tidy/checkers/readability-magic-numbers-bitfields.cpp @@ -0,0 +1,22 @@ +// RUN: %check_clang_tidy %s readability-magic-numbers %t \ +// RUN: -config='{CheckOptions: \ +// RUN: [{key: readability-magic-numbers.IgnoredIntegerValues, value: "1;2;10;100;"}]}' \ +// RUN: -- + +struct HardwareGateway { + /* + * The configuration suppresses the warnings for the bitfields... + */ + unsigned int Some: 5; + unsigned int Bits: 7; + unsigned int: 7; + unsigned int: 0; + unsigned int Rest: 13; + + /* + * ... but other fields trigger the warning. + */ + unsigned int Another[3]; + // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: 3 is a magic number; consider replacing it with a named constant [readability-magic-numbers] +}; + diff --git a/clang-tools-extra/test/clang-tidy/checkers/readability-magic-numbers.cpp b/clang-tools-extra/test/clang-tidy/checkers/readability-magic-numbers.cpp index 3cf9dc52ea2..055ad76d09b 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/readability-magic-numbers.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/readability-magic-numbers.cpp @@ -2,6 +2,7 @@ // RUN: -config='{CheckOptions: \ // RUN: [{key: readability-magic-numbers.IgnoredIntegerValues, value: "0;1;2;10;100;"}, \ // RUN: {key: readability-magic-numbers.IgnoredFloatingPointValues, value: "3.14;2.71828;9.81;10000.0;101.0;0x1.2p3"}, \ +// RUN: {key: readability-magic-numbers.IgnoreBitFieldsWidths, value: 0}, \ // RUN: {key: readability-magic-numbers.IgnorePowersOf2IntegerValues, value: 1}]}' \ // RUN: -- @@ -79,6 +80,23 @@ int getAnswer() { // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: 3 is a magic number; consider replacing it with a named constant [readability-magic-numbers] } +struct HardwareGateway { + unsigned int Some: 5; + // CHECK-MESSAGES: :[[@LINE-1]]:23: warning: 5 is a magic number; consider replacing it with a named constant [readability-magic-numbers] + unsigned int Bits: 7; + // CHECK-MESSAGES: :[[@LINE-1]]:23: warning: 7 is a magic number; consider replacing it with a named constant [readability-magic-numbers] + unsigned int: 6; + // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: 6 is a magic number; consider replacing it with a named constant [readability-magic-numbers] + unsigned int Flag: 1; // no warning since this is suppressed by IgnoredIntegerValues rule + unsigned int: 0; // no warning since this is suppressed by IgnoredIntegerValues rule + unsigned int Rest: 13; + // CHECK-MESSAGES: :[[@LINE-1]]:23: warning: 13 is a magic number; consider replacing it with a named constant [readability-magic-numbers] + // + unsigned int Another[3]; + // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: 3 is a magic number; consider replacing it with a named constant [readability-magic-numbers] +}; + + /* * Clean code */ |

