diff options
Diffstat (limited to 'tools/clang-tidy/test')
201 files changed, 1330 insertions, 0 deletions
diff --git a/tools/clang-tidy/test/bugprone-argument-comment.cpp b/tools/clang-tidy/test/bugprone-argument-comment.cpp new file mode 100644 index 0000000000..3099575a35 --- /dev/null +++ b/tools/clang-tidy/test/bugprone-argument-comment.cpp @@ -0,0 +1,6 @@ +// bugprone-argument-comment + +void f(int x, int y); +void g() { + f(/*y=*/0, /*z=*/0); +} diff --git a/tools/clang-tidy/test/bugprone-argument-comment.json b/tools/clang-tidy/test/bugprone-argument-comment.json new file mode 100644 index 0000000000..4890f4b315 --- /dev/null +++ b/tools/clang-tidy/test/bugprone-argument-comment.json @@ -0,0 +1 @@ +[["warning", "argument name 'y' in comment does not match parameter name 'x'", "bugprone-argument-comment"], ["warning", "argument name 'z' in comment does not match parameter name 'y'", "bugprone-argument-comment"], {"reliability": "high"}]
\ No newline at end of file diff --git a/tools/clang-tidy/test/bugprone-assert-side-effect.cpp b/tools/clang-tidy/test/bugprone-assert-side-effect.cpp new file mode 100644 index 0000000000..7cc0a79cf1 --- /dev/null +++ b/tools/clang-tidy/test/bugprone-assert-side-effect.cpp @@ -0,0 +1,8 @@ +#include "structures.h" + +// bugprone-assert-side-effect +void misc_assert_side_effect() { + int X = 0; + assert(X == 1); + assert(X = 1); +} diff --git a/tools/clang-tidy/test/bugprone-assert-side-effect.json b/tools/clang-tidy/test/bugprone-assert-side-effect.json new file mode 100644 index 0000000000..54ca571b05 --- /dev/null +++ b/tools/clang-tidy/test/bugprone-assert-side-effect.json @@ -0,0 +1 @@ +[["warning", "found assert() with side effect", "bugprone-assert-side-effect"], {"reliability": "high"}]
\ No newline at end of file diff --git a/tools/clang-tidy/test/bugprone-bool-pointer-implicit-conversion.cpp b/tools/clang-tidy/test/bugprone-bool-pointer-implicit-conversion.cpp new file mode 100644 index 0000000000..602fa9a578 --- /dev/null +++ b/tools/clang-tidy/test/bugprone-bool-pointer-implicit-conversion.cpp @@ -0,0 +1,20 @@ +// https://clang.llvm.org/extra/clang-tidy/checks/bugprone-bool-pointer-implicit-conversion.html + +bool test(bool* pointer_to_bool, int* pointer_to_int) +{ + if (pointer_to_bool) { // warning for pointer to bool + } + + if (pointer_to_int) { // no warning for pointer to int + } + + if (!pointer_to_bool) { // no warning, but why not?? + } + + if (pointer_to_bool != nullptr) { // no warning for nullptr comparison + } + + // no warning on return, but why not?? + // clang-tidy bug: https://bugs.llvm.org/show_bug.cgi?id=38060 + return pointer_to_bool; +} diff --git a/tools/clang-tidy/test/bugprone-bool-pointer-implicit-conversion.json b/tools/clang-tidy/test/bugprone-bool-pointer-implicit-conversion.json new file mode 100644 index 0000000000..23bd6071ba --- /dev/null +++ b/tools/clang-tidy/test/bugprone-bool-pointer-implicit-conversion.json @@ -0,0 +1 @@ +[["warning", "dubious check of 'bool *' against 'nullptr', did you mean to dereference it?", "bugprone-bool-pointer-implicit-conversion"], {"reliability": "low"}]
\ No newline at end of file diff --git a/tools/clang-tidy/test/bugprone-forward-declaration-namespace.cpp b/tools/clang-tidy/test/bugprone-forward-declaration-namespace.cpp new file mode 100644 index 0000000000..f93d54b0a1 --- /dev/null +++ b/tools/clang-tidy/test/bugprone-forward-declaration-namespace.cpp @@ -0,0 +1,3 @@ +namespace na { struct A; } +namespace nb { struct A {}; } +nb::A a; diff --git a/tools/clang-tidy/test/bugprone-forward-declaration-namespace.json b/tools/clang-tidy/test/bugprone-forward-declaration-namespace.json new file mode 100644 index 0000000000..be3b5cbb5b --- /dev/null +++ b/tools/clang-tidy/test/bugprone-forward-declaration-namespace.json @@ -0,0 +1 @@ +[["warning", "no definition found for 'A', but a definition with the same name 'A' found in another namespace 'nb'", "bugprone-forward-declaration-namespace"], {"reliability": "high"}]
\ No newline at end of file diff --git a/tools/clang-tidy/test/bugprone-incorrect-roundings.cpp b/tools/clang-tidy/test/bugprone-incorrect-roundings.cpp new file mode 100644 index 0000000000..ee37b56ae0 --- /dev/null +++ b/tools/clang-tidy/test/bugprone-incorrect-roundings.cpp @@ -0,0 +1,7 @@ +void f1() +{ + double d; + int x; + + x = (d + 0.5); +} diff --git a/tools/clang-tidy/test/bugprone-incorrect-roundings.json b/tools/clang-tidy/test/bugprone-incorrect-roundings.json new file mode 100644 index 0000000000..7ee4c763af --- /dev/null +++ b/tools/clang-tidy/test/bugprone-incorrect-roundings.json @@ -0,0 +1 @@ +[["warning", "casting (double + 0.5) to integer leads to incorrect rounding; consider using lround (#include <cmath>) instead", "bugprone-incorrect-roundings"], {"reliability": "high"}]
\ No newline at end of file diff --git a/tools/clang-tidy/test/bugprone-integer-division.cpp b/tools/clang-tidy/test/bugprone-integer-division.cpp new file mode 100644 index 0000000000..058edffe39 --- /dev/null +++ b/tools/clang-tidy/test/bugprone-integer-division.cpp @@ -0,0 +1,5 @@ +float f() { + int a = 2; + int b = 10; + return a/b; +} diff --git a/tools/clang-tidy/test/bugprone-integer-division.json b/tools/clang-tidy/test/bugprone-integer-division.json new file mode 100644 index 0000000000..c90b0f7066 --- /dev/null +++ b/tools/clang-tidy/test/bugprone-integer-division.json @@ -0,0 +1 @@ +[["warning", "result of integer division used in a floating point context; possible loss of precision", "bugprone-integer-division"], {"reliability": "high"}]
\ No newline at end of file diff --git a/tools/clang-tidy/test/bugprone-macro-parentheses.cpp b/tools/clang-tidy/test/bugprone-macro-parentheses.cpp new file mode 100644 index 0000000000..53c22090a1 --- /dev/null +++ b/tools/clang-tidy/test/bugprone-macro-parentheses.cpp @@ -0,0 +1,5 @@ +#define BAD1 -1 +#define BAD2 1+2 +#define BAD3(A) (A+1) +#define BAD4(x) ((unsigned char)(x & 0xff)) +#define BAD5(X) A*B=(C*)X+2 diff --git a/tools/clang-tidy/test/bugprone-macro-parentheses.json b/tools/clang-tidy/test/bugprone-macro-parentheses.json new file mode 100644 index 0000000000..8fa0a13d04 --- /dev/null +++ b/tools/clang-tidy/test/bugprone-macro-parentheses.json @@ -0,0 +1 @@ +[["warning", "macro replacement list should be enclosed in parentheses", "bugprone-macro-parentheses"], ["warning", "macro replacement list should be enclosed in parentheses", "bugprone-macro-parentheses"], ["warning", "macro argument should be enclosed in parentheses", "bugprone-macro-parentheses"], ["warning", "macro argument should be enclosed in parentheses", "bugprone-macro-parentheses"], ["warning", "macro argument should be enclosed in parentheses", "bugprone-macro-parentheses"], {"reliability": "medium"}]
\ No newline at end of file diff --git a/tools/clang-tidy/test/bugprone-macro-repeated-side-effects.cpp b/tools/clang-tidy/test/bugprone-macro-repeated-side-effects.cpp new file mode 100644 index 0000000000..2dedb3aca9 --- /dev/null +++ b/tools/clang-tidy/test/bugprone-macro-repeated-side-effects.cpp @@ -0,0 +1,28 @@ +// https://clang.llvm.org/extra/clang-tidy/checks/bugprone-macro-repeated-side-effects.html + +#define MACRO_WITHOUT_REPEATED_ARG(x) (x) +#define MACRO_WITH_REPEATED_ARG(x) ((x) + (x)) + +static int g; + +int function_with_side_effects(int i) +{ + g += i; + return g; +} + +void test() +{ + int i; + i = MACRO_WITHOUT_REPEATED_ARG(1); // OK + i = MACRO_WITH_REPEATED_ARG(1); // OK + + i = MACRO_WITHOUT_REPEATED_ARG(i); // OK + i = MACRO_WITH_REPEATED_ARG(i); // OK + + i = MACRO_WITHOUT_REPEATED_ARG(function_with_side_effects(i)); // OK + i = MACRO_WITH_REPEATED_ARG(function_with_side_effects(i)); // NO WARNING + + i = MACRO_WITHOUT_REPEATED_ARG(i++); // OK + i = MACRO_WITH_REPEATED_ARG(i++); // WARNING +} diff --git a/tools/clang-tidy/test/bugprone-macro-repeated-side-effects.json b/tools/clang-tidy/test/bugprone-macro-repeated-side-effects.json new file mode 100644 index 0000000000..e3b6719b95 --- /dev/null +++ b/tools/clang-tidy/test/bugprone-macro-repeated-side-effects.json @@ -0,0 +1 @@ +[["warning", "side effects in the 1st macro argument 'x' are repeated in macro expansion", "bugprone-macro-repeated-side-effects"], {"reliability": "high"}]
\ No newline at end of file diff --git a/tools/clang-tidy/test/bugprone-misplaced-widening-cast.cpp b/tools/clang-tidy/test/bugprone-misplaced-widening-cast.cpp new file mode 100644 index 0000000000..e75541bf6e --- /dev/null +++ b/tools/clang-tidy/test/bugprone-misplaced-widening-cast.cpp @@ -0,0 +1,3 @@ +long f(int x) { + return (long)(x * 1000); +} diff --git a/tools/clang-tidy/test/bugprone-misplaced-widening-cast.json b/tools/clang-tidy/test/bugprone-misplaced-widening-cast.json new file mode 100644 index 0000000000..edf976dcff --- /dev/null +++ b/tools/clang-tidy/test/bugprone-misplaced-widening-cast.json @@ -0,0 +1 @@ +[["warning", "either cast from 'int' to 'long' is ineffective, or there is loss of precision before the conversion", "bugprone-misplaced-widening-cast"], {"reliability": "high"}]
\ No newline at end of file diff --git a/tools/clang-tidy/test/bugprone-move-forwarding-reference.cpp b/tools/clang-tidy/test/bugprone-move-forwarding-reference.cpp new file mode 100644 index 0000000000..45be15ee65 --- /dev/null +++ b/tools/clang-tidy/test/bugprone-move-forwarding-reference.cpp @@ -0,0 +1,25 @@ + +namespace std { +template <typename> struct remove_reference; + +template <typename _Tp> struct remove_reference { typedef _Tp type; }; + +template <typename _Tp> struct remove_reference<_Tp &> { typedef _Tp type; }; + +template <typename _Tp> struct remove_reference<_Tp &&> { typedef _Tp type; }; + +template <typename _Tp> +constexpr typename std::remove_reference<_Tp>::type &&move(_Tp &&__t); + +} // namespace std + +// Standard case. +template <typename T, typename U> void f1(U &&SomeU) { + T SomeT(std::move(SomeU)); + // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: forwarding reference passed to + // CHECK-FIXES: T SomeT(std::forward<U>(SomeU)); +} + +void foo() { + f1<int, int>(2); +} diff --git a/tools/clang-tidy/test/bugprone-move-forwarding-reference.json b/tools/clang-tidy/test/bugprone-move-forwarding-reference.json new file mode 100644 index 0000000000..a77beede11 --- /dev/null +++ b/tools/clang-tidy/test/bugprone-move-forwarding-reference.json @@ -0,0 +1 @@ +[["warning", "forwarding reference passed to std::move(), which may unexpectedly cause lvalues to be moved; use std::forward() instead", "bugprone-move-forwarding-reference"], {"reliability": "high"}]
\ No newline at end of file diff --git a/tools/clang-tidy/test/bugprone-multiple-statement-macro.cpp b/tools/clang-tidy/test/bugprone-multiple-statement-macro.cpp new file mode 100644 index 0000000000..7ad2a2df64 --- /dev/null +++ b/tools/clang-tidy/test/bugprone-multiple-statement-macro.cpp @@ -0,0 +1,10 @@ +void F(); + +#define BAD_MACRO(x) \ + F(); \ + F() + +void positives() { + if (1) + BAD_MACRO(1); +} diff --git a/tools/clang-tidy/test/bugprone-multiple-statement-macro.json b/tools/clang-tidy/test/bugprone-multiple-statement-macro.json new file mode 100644 index 0000000000..86c5f0f9f4 --- /dev/null +++ b/tools/clang-tidy/test/bugprone-multiple-statement-macro.json @@ -0,0 +1 @@ +[["warning", "multiple statement macro used without braces; some statements will be unconditionally executed", "bugprone-multiple-statement-macro"]]
\ No newline at end of file diff --git a/tools/clang-tidy/test/bugprone-sizeof-expression.cpp b/tools/clang-tidy/test/bugprone-sizeof-expression.cpp new file mode 100644 index 0000000000..f5f1f469ce --- /dev/null +++ b/tools/clang-tidy/test/bugprone-sizeof-expression.cpp @@ -0,0 +1,3 @@ +class C { + int size() { return sizeof(this); } +}; diff --git a/tools/clang-tidy/test/bugprone-sizeof-expression.json b/tools/clang-tidy/test/bugprone-sizeof-expression.json new file mode 100644 index 0000000000..777a20d328 --- /dev/null +++ b/tools/clang-tidy/test/bugprone-sizeof-expression.json @@ -0,0 +1 @@ +[["warning", "suspicious usage of 'sizeof(this)'; did you mean 'sizeof(*this)'", "bugprone-sizeof-expression"], {"reliability": "high"}]
\ No newline at end of file diff --git a/tools/clang-tidy/test/bugprone-string-constructor.cpp b/tools/clang-tidy/test/bugprone-string-constructor.cpp new file mode 100644 index 0000000000..8b6a4980a3 --- /dev/null +++ b/tools/clang-tidy/test/bugprone-string-constructor.cpp @@ -0,0 +1,17 @@ +// https://clang.llvm.org/extra/clang-tidy/checks/bugprone-string-constructor.html + +#include "structures.h" + +void test() +{ + // A common mistake is to swap parameters to the ‘fill’ string-constructor. + std::string str('x', 50); // should be str(50, 'x') + + // Calling the string-literal constructor with a length bigger than the + // literal is suspicious and adds extra random characters to the string. + std::string("test", 200); // Will include random characters after "test". + + // Creating an empty string from constructors with parameters is considered + // suspicious. The programmer should use the empty constructor instead. + std::string("test", 0); // Creation of an empty string. +} diff --git a/tools/clang-tidy/test/bugprone-string-constructor.json b/tools/clang-tidy/test/bugprone-string-constructor.json new file mode 100644 index 0000000000..99211f27a4 --- /dev/null +++ b/tools/clang-tidy/test/bugprone-string-constructor.json @@ -0,0 +1 @@ +[["warning", "string constructor parameters are probably swapped; expecting string(count, character)", "bugprone-string-constructor"], ["warning", "length is bigger than string literal size", "bugprone-string-constructor"], ["warning", "constructor creating an empty string", "bugprone-string-constructor"], {"reliability": "high"}]
\ No newline at end of file diff --git a/tools/clang-tidy/test/bugprone-string-integer-assignment.cpp b/tools/clang-tidy/test/bugprone-string-integer-assignment.cpp new file mode 100644 index 0000000000..30ef46b922 --- /dev/null +++ b/tools/clang-tidy/test/bugprone-string-integer-assignment.cpp @@ -0,0 +1,28 @@ +// https://clang.llvm.org/extra/clang-tidy/checks/bugprone-string-integer-assignment.html + +#include "structures.h" + +void test_int() +{ + // Numeric types can be implicitly casted to character types. + std::string s; + int x = 5965; + s = 6; // warning + s = x; // warning +} + +void test_conversion() +{ + // Use the appropriate conversion functions or character literals. + std::string s; + int x = 5965; + s = '6'; // OK + s = std::to_string(x); // OK +} + +void test_cast() +{ + // In order to suppress false positives, use an explicit cast. + std::string s; + s = static_cast<char>(6); // OK +} diff --git a/tools/clang-tidy/test/bugprone-string-integer-assignment.json b/tools/clang-tidy/test/bugprone-string-integer-assignment.json new file mode 100644 index 0000000000..e7cbe1190f --- /dev/null +++ b/tools/clang-tidy/test/bugprone-string-integer-assignment.json @@ -0,0 +1 @@ +[["warning", "an integer is interpreted as a character code when assigning it to a string; if this is intended, cast the integer to the appropriate character type; if you want a string representation, use the appropriate conversion facility", "bugprone-string-integer-assignment"], ["warning", "an integer is interpreted as a character code when assigning it to a string; if this is intended, cast the integer to the appropriate character type; if you want a string representation, use the appropriate conversion facility", "bugprone-string-integer-assignment"], {"reliability": "high"}]
\ No newline at end of file diff --git a/tools/clang-tidy/test/bugprone-suspicious-memset-usage.cpp b/tools/clang-tidy/test/bugprone-suspicious-memset-usage.cpp new file mode 100644 index 0000000000..71fe7239a1 --- /dev/null +++ b/tools/clang-tidy/test/bugprone-suspicious-memset-usage.cpp @@ -0,0 +1,22 @@ +// https://clang.llvm.org/extra/clang-tidy/checks/bugprone-suspicious-memset-usage.html + +#include "structures.h" + +void test(int* ip, char* cp) +{ + // Case 1: Fill value is a character '0' instead of NUL '\0'. + memset(ip, '0', 1); // WARNING: suspicious for non-char pointers + memset(cp, '0', 1); // OK for char pointers + + // Case 2: Fill value is truncated. + memset(ip, 0xabcd, 1); // WARNING: fill value gets truncated + memset(ip, 0x00cd, 1); // OK because value 0xcd is not truncated. + memset(ip, 0x00, 1); // OK because value is not truncated. + + // Case 3: Byte count is zero. + memset(ip, sizeof(int), 0); // WARNING: zero length, potentially swapped + memset(ip, sizeof(int), 1); // OK with non-zero length + + // See clang bug https://bugs.llvm.org/show_bug.cgi?id=38098 + memset(ip, 8, 0); // OK with zero length without sizeof +} diff --git a/tools/clang-tidy/test/bugprone-suspicious-memset-usage.json b/tools/clang-tidy/test/bugprone-suspicious-memset-usage.json new file mode 100644 index 0000000000..49b1c5b04e --- /dev/null +++ b/tools/clang-tidy/test/bugprone-suspicious-memset-usage.json @@ -0,0 +1 @@ +[["warning", "memset fill value is char '0', potentially mistaken for int 0", "bugprone-suspicious-memset-usage"], ["warning", "memset fill value is out of unsigned character range, gets truncated", "bugprone-suspicious-memset-usage"], ["warning", "memset of size zero, potentially swapped arguments", "bugprone-suspicious-memset-usage"], {"reliability": "high"}]
\ No newline at end of file diff --git a/tools/clang-tidy/test/bugprone-suspicious-missing-comma.cpp b/tools/clang-tidy/test/bugprone-suspicious-missing-comma.cpp new file mode 100644 index 0000000000..de1634e11f --- /dev/null +++ b/tools/clang-tidy/test/bugprone-suspicious-missing-comma.cpp @@ -0,0 +1,9 @@ +const char* Cartoons[] = { + "Bugs Bunny", + "Homer Simpson", + "Mickey Mouse", + "Bart Simpson", + "Charlie Brown" // There is a missing comma here. + "Fred Flintstone", + "Popeye", +}; diff --git a/tools/clang-tidy/test/bugprone-suspicious-missing-comma.json b/tools/clang-tidy/test/bugprone-suspicious-missing-comma.json new file mode 100644 index 0000000000..a7e3714236 --- /dev/null +++ b/tools/clang-tidy/test/bugprone-suspicious-missing-comma.json @@ -0,0 +1 @@ +[["warning", "suspicious string literal, probably missing a comma", "bugprone-suspicious-missing-comma"], {"reliability": "high"}]
\ No newline at end of file diff --git a/tools/clang-tidy/test/bugprone-suspicious-semicolon.cpp b/tools/clang-tidy/test/bugprone-suspicious-semicolon.cpp new file mode 100644 index 0000000000..7a90a87cd3 --- /dev/null +++ b/tools/clang-tidy/test/bugprone-suspicious-semicolon.cpp @@ -0,0 +1,8 @@ + +// bugprone-suspicious-semicolon +void nop(); +void fail1() +{ + int x = 0; + if(x > 5); nop(); +} diff --git a/tools/clang-tidy/test/bugprone-suspicious-semicolon.json b/tools/clang-tidy/test/bugprone-suspicious-semicolon.json new file mode 100644 index 0000000000..30116ed3a1 --- /dev/null +++ b/tools/clang-tidy/test/bugprone-suspicious-semicolon.json @@ -0,0 +1 @@ +[["warning", "potentially unintended semicolon", "bugprone-suspicious-semicolon"], {"reliability": "high"}]
\ No newline at end of file diff --git a/tools/clang-tidy/test/bugprone-suspicious-string-compare.cpp b/tools/clang-tidy/test/bugprone-suspicious-string-compare.cpp new file mode 100644 index 0000000000..505a9d282c --- /dev/null +++ b/tools/clang-tidy/test/bugprone-suspicious-string-compare.cpp @@ -0,0 +1,8 @@ +static const char A[] = "abc"; + +int strcmp(const char *, const char *); + +int test_warning_patterns() { + if (strcmp(A, "a")) + return 0; +} diff --git a/tools/clang-tidy/test/bugprone-suspicious-string-compare.json b/tools/clang-tidy/test/bugprone-suspicious-string-compare.json new file mode 100644 index 0000000000..0def2de1f1 --- /dev/null +++ b/tools/clang-tidy/test/bugprone-suspicious-string-compare.json @@ -0,0 +1 @@ +[["warning", "function 'strcmp' is called without explicitly comparing result", "bugprone-suspicious-string-compare"], {"reliability": "high"}]
\ No newline at end of file diff --git a/tools/clang-tidy/test/bugprone-swapped-arguments.cpp b/tools/clang-tidy/test/bugprone-swapped-arguments.cpp new file mode 100644 index 0000000000..074df52050 --- /dev/null +++ b/tools/clang-tidy/test/bugprone-swapped-arguments.cpp @@ -0,0 +1,26 @@ +// https://clang.llvm.org/extra/clang-tidy/checks/bugprone-swapped-arguments.html + +void test_d_i(double d, int i); +void test_d_i_i(double d, int i, int ii); +void test_i_d(int i, double d); +void test_i_i_d(int i, int ii, double d); + +void test() +{ + double d = 1; + int i = 1; + + test_d_i(d, i); // OK + test_d_i(i, d); // WARNING + + test_i_d(i, d); // OK + test_i_d(d, i); // WARNING + + test_i_i_d(i, i, d); // OK + test_i_i_d(i, d, i); // WARNING + test_i_i_d(d, i, i); // NO WARNING after second parameter + + test_d_i_i(d, i, i); // OK + test_d_i_i(i, d, i); // WARNING + test_d_i_i(i, i, d); // NO WARNING after second parameter +} diff --git a/tools/clang-tidy/test/bugprone-swapped-arguments.json b/tools/clang-tidy/test/bugprone-swapped-arguments.json new file mode 100644 index 0000000000..35d5cbdb72 --- /dev/null +++ b/tools/clang-tidy/test/bugprone-swapped-arguments.json @@ -0,0 +1 @@ +[["warning", "argument with implicit conversion from 'double' to 'int' followed by argument converted from 'int' to 'double', potentially swapped arguments.", "bugprone-swapped-arguments"], ["warning", "argument with implicit conversion from 'int' to 'double' followed by argument converted from 'double' to 'int', potentially swapped arguments.", "bugprone-swapped-arguments"], ["warning", "argument with implicit conversion from 'int' to 'double' followed by argument converted from 'double' to 'int', potentially swapped arguments.", "bugprone-swapped-arguments"], ["warning", "argument with implicit conversion from 'double' to 'int' followed by argument converted from 'int' to 'double', potentially swapped arguments.", "bugprone-swapped-arguments"], {"reliability": "high"}]
\ No newline at end of file diff --git a/tools/clang-tidy/test/bugprone-too-small-loop-variable.cpp b/tools/clang-tidy/test/bugprone-too-small-loop-variable.cpp new file mode 100644 index 0000000000..4dc8ed7a22 --- /dev/null +++ b/tools/clang-tidy/test/bugprone-too-small-loop-variable.cpp @@ -0,0 +1,4 @@ +int main() { + long size = 294967296l; + for (short i = 0; i < size; ++i) {} +} diff --git a/tools/clang-tidy/test/bugprone-too-small-loop-variable.json b/tools/clang-tidy/test/bugprone-too-small-loop-variable.json new file mode 100644 index 0000000000..073c520f00 --- /dev/null +++ b/tools/clang-tidy/test/bugprone-too-small-loop-variable.json @@ -0,0 +1 @@ +[["warning", "loop variable has narrower type 'short' than iteration's upper bound 'long'", "bugprone-too-small-loop-variable"], {"reliability": "high"}]
\ No newline at end of file diff --git a/tools/clang-tidy/test/bugprone-unused-raii.cpp b/tools/clang-tidy/test/bugprone-unused-raii.cpp new file mode 100644 index 0000000000..6a4a0a15ab --- /dev/null +++ b/tools/clang-tidy/test/bugprone-unused-raii.cpp @@ -0,0 +1,25 @@ +// https://clang.llvm.org/extra/clang-tidy/checks/bugprone-unused-raii.html + +struct scoped_lock +{ + scoped_lock() {} + ~scoped_lock() {} +}; + +#define SCOPED_LOCK_MACRO(m) scoped_lock() + +struct trivial_scoped_lock +{ + trivial_scoped_lock() {} +}; + +scoped_lock test() +{ + scoped_lock(); // misc-unused-raii warning! + + SCOPED_LOCK_MACRO(); // no warning for macros + + trivial_scoped_lock(); // no warning for trivial objects without destructors + + return scoped_lock(); // no warning for return values +} diff --git a/tools/clang-tidy/test/bugprone-unused-raii.json b/tools/clang-tidy/test/bugprone-unused-raii.json new file mode 100644 index 0000000000..d9eb8dd9b6 --- /dev/null +++ b/tools/clang-tidy/test/bugprone-unused-raii.json @@ -0,0 +1 @@ +[["warning", "object destroyed immediately after creation; did you mean to name the object?", "bugprone-unused-raii"], {"reliability": "high"}]
\ No newline at end of file diff --git a/tools/clang-tidy/test/bugprone-use-after-move.cpp b/tools/clang-tidy/test/bugprone-use-after-move.cpp new file mode 100644 index 0000000000..f90a8700d6 --- /dev/null +++ b/tools/clang-tidy/test/bugprone-use-after-move.cpp @@ -0,0 +1,62 @@ +namespace std { +typedef unsigned size_t; + +template <typename T> +struct unique_ptr { + unique_ptr(); + T *get() const; + explicit operator bool() const; + void reset(T *ptr); + T &operator*() const; + T *operator->() const; + T& operator[](size_t i) const; +}; + +template <typename> +struct remove_reference; + +template <typename _Tp> +struct remove_reference { + typedef _Tp type; +}; + +template <typename _Tp> +struct remove_reference<_Tp &> { + typedef _Tp type; +}; + +template <typename _Tp> +struct remove_reference<_Tp &&> { + typedef _Tp type; +}; + +template <typename _Tp> +constexpr typename std::remove_reference<_Tp>::type &&move(_Tp &&__t) noexcept { + return static_cast<typename remove_reference<_Tp>::type &&>(__t); +} +} + +class A { +public: + A(); + A(const A &); + A(A &&); + + A &operator=(const A &); + A &operator=(A &&); + + void foo() const; + int getInt() const; + + operator bool() const; + + int i; +}; + +void func() { + std::unique_ptr<A> ptr; + std::move(ptr); + ptr.get(); + static_cast<bool>(ptr); + *ptr; +} diff --git a/tools/clang-tidy/test/bugprone-use-after-move.json b/tools/clang-tidy/test/bugprone-use-after-move.json new file mode 100644 index 0000000000..91b9943e92 --- /dev/null +++ b/tools/clang-tidy/test/bugprone-use-after-move.json @@ -0,0 +1 @@ +[["warning", "'ptr' used after it was moved", "bugprone-use-after-move"], {"reliability": "high"}]
\ No newline at end of file diff --git a/tools/clang-tidy/test/clang-analyzer-core.CallAndMessage.cpp b/tools/clang-tidy/test/clang-analyzer-core.CallAndMessage.cpp new file mode 100644 index 0000000000..286189e25b --- /dev/null +++ b/tools/clang-tidy/test/clang-analyzer-core.CallAndMessage.cpp @@ -0,0 +1,10 @@ +struct S { + int x; +}; + +void f(struct S s); + +void test() { + struct S s; + f(s); +} diff --git a/tools/clang-tidy/test/clang-analyzer-core.CallAndMessage.json b/tools/clang-tidy/test/clang-analyzer-core.CallAndMessage.json new file mode 100644 index 0000000000..45a42b989a --- /dev/null +++ b/tools/clang-tidy/test/clang-analyzer-core.CallAndMessage.json @@ -0,0 +1 @@ +[["warning", "Passed-by-value struct argument contains uninitialized data (e.g., field: 'x')", "clang-analyzer-core.CallAndMessage"], {"reliability": "medium"}]
\ No newline at end of file diff --git a/tools/clang-tidy/test/clang-analyzer-core.DivideZero.cpp b/tools/clang-tidy/test/clang-analyzer-core.DivideZero.cpp new file mode 100644 index 0000000000..aac9f7c9f6 --- /dev/null +++ b/tools/clang-tidy/test/clang-analyzer-core.DivideZero.cpp @@ -0,0 +1,4 @@ +void test(int z) { + if (z == 0) + int x = 1 / z; +} diff --git a/tools/clang-tidy/test/clang-analyzer-core.DivideZero.json b/tools/clang-tidy/test/clang-analyzer-core.DivideZero.json new file mode 100644 index 0000000000..ba045635e2 --- /dev/null +++ b/tools/clang-tidy/test/clang-analyzer-core.DivideZero.json @@ -0,0 +1 @@ +[["warning", "Division by zero", "clang-analyzer-core.DivideZero"], {"reliability": "high"}]
\ No newline at end of file diff --git a/tools/clang-tidy/test/clang-analyzer-core.NonNullParamChecker.cpp b/tools/clang-tidy/test/clang-analyzer-core.NonNullParamChecker.cpp new file mode 100644 index 0000000000..bc071f5453 --- /dev/null +++ b/tools/clang-tidy/test/clang-analyzer-core.NonNullParamChecker.cpp @@ -0,0 +1,6 @@ +int f(int *p) __attribute__((nonnull)); + +void test(int *p) { + if (!p) + f(p); // warn +} diff --git a/tools/clang-tidy/test/clang-analyzer-core.NonNullParamChecker.json b/tools/clang-tidy/test/clang-analyzer-core.NonNullParamChecker.json new file mode 100644 index 0000000000..6c4b361150 --- /dev/null +++ b/tools/clang-tidy/test/clang-analyzer-core.NonNullParamChecker.json @@ -0,0 +1 @@ +[["warning", "Null pointer passed to 1st parameter expecting 'nonnull'", "clang-analyzer-core.NonNullParamChecker"], {"reliability": "high"}]
\ No newline at end of file diff --git a/tools/clang-tidy/test/clang-analyzer-core.NullDereference.cpp b/tools/clang-tidy/test/clang-analyzer-core.NullDereference.cpp new file mode 100644 index 0000000000..6c9c555532 --- /dev/null +++ b/tools/clang-tidy/test/clang-analyzer-core.NullDereference.cpp @@ -0,0 +1,9 @@ +class C { +public: + int x; +}; + +void test() { + C *pc = 0; + int k = pc->x; +} diff --git a/tools/clang-tidy/test/clang-analyzer-core.NullDereference.json b/tools/clang-tidy/test/clang-analyzer-core.NullDereference.json new file mode 100644 index 0000000000..001177f1da --- /dev/null +++ b/tools/clang-tidy/test/clang-analyzer-core.NullDereference.json @@ -0,0 +1 @@ +[["warning", "Access to field 'x' results in a dereference of a null pointer (loaded from variable 'pc')", "clang-analyzer-core.NullDereference"], {"reliability": "medium"}]
\ No newline at end of file diff --git a/tools/clang-tidy/test/clang-analyzer-core.UndefinedBinaryOperatorResult.cpp b/tools/clang-tidy/test/clang-analyzer-core.UndefinedBinaryOperatorResult.cpp new file mode 100644 index 0000000000..1351c35f44 --- /dev/null +++ b/tools/clang-tidy/test/clang-analyzer-core.UndefinedBinaryOperatorResult.cpp @@ -0,0 +1,4 @@ +void test() { + int x; + int y = x + 1; +} diff --git a/tools/clang-tidy/test/clang-analyzer-core.UndefinedBinaryOperatorResult.json b/tools/clang-tidy/test/clang-analyzer-core.UndefinedBinaryOperatorResult.json new file mode 100644 index 0000000000..5b1fc15485 --- /dev/null +++ b/tools/clang-tidy/test/clang-analyzer-core.UndefinedBinaryOperatorResult.json @@ -0,0 +1 @@ +[["warning", "The left operand of '+' is a garbage value", "clang-analyzer-core.UndefinedBinaryOperatorResult"], {"reliability": "medium"}]
\ No newline at end of file diff --git a/tools/clang-tidy/test/clang-analyzer-core.uninitialized.Assign.cpp b/tools/clang-tidy/test/clang-analyzer-core.uninitialized.Assign.cpp new file mode 100644 index 0000000000..e9685d48a4 --- /dev/null +++ b/tools/clang-tidy/test/clang-analyzer-core.uninitialized.Assign.cpp @@ -0,0 +1,4 @@ +void test() { + int x; + x |= 1; +} diff --git a/tools/clang-tidy/test/clang-analyzer-core.uninitialized.Assign.json b/tools/clang-tidy/test/clang-analyzer-core.uninitialized.Assign.json new file mode 100644 index 0000000000..1fd521a6ec --- /dev/null +++ b/tools/clang-tidy/test/clang-analyzer-core.uninitialized.Assign.json @@ -0,0 +1 @@ +[["warning", "The left expression of the compound assignment is an uninitialized value. The computed value will also be garbage", "clang-analyzer-core.uninitialized.Assign"], {"reliability": "medium"}]
\ No newline at end of file diff --git a/tools/clang-tidy/test/clang-analyzer-core.uninitialized.Branch.cpp b/tools/clang-tidy/test/clang-analyzer-core.uninitialized.Branch.cpp new file mode 100644 index 0000000000..7a985eb080 --- /dev/null +++ b/tools/clang-tidy/test/clang-analyzer-core.uninitialized.Branch.cpp @@ -0,0 +1,6 @@ +void test() { + int x; + if (x) { + return; + } +} diff --git a/tools/clang-tidy/test/clang-analyzer-core.uninitialized.Branch.json b/tools/clang-tidy/test/clang-analyzer-core.uninitialized.Branch.json new file mode 100644 index 0000000000..d768aa6eed --- /dev/null +++ b/tools/clang-tidy/test/clang-analyzer-core.uninitialized.Branch.json @@ -0,0 +1 @@ +[["warning", "Branch condition evaluates to a garbage value", "clang-analyzer-core.uninitialized.Branch"], {"reliability": "medium"}]
\ No newline at end of file diff --git a/tools/clang-tidy/test/clang-analyzer-cplusplus.Move.cpp b/tools/clang-tidy/test/clang-analyzer-cplusplus.Move.cpp new file mode 100644 index 0000000000..65f2e36561 --- /dev/null +++ b/tools/clang-tidy/test/clang-analyzer-cplusplus.Move.cpp @@ -0,0 +1,10 @@ +class P {}; + +void bar(P) {} + +void foo(int n) { + P x; + for (int i = n; i >= 0; --i) { + bar(static_cast<P&&>(x)); + } +} diff --git a/tools/clang-tidy/test/clang-analyzer-cplusplus.Move.json b/tools/clang-tidy/test/clang-analyzer-cplusplus.Move.json new file mode 100644 index 0000000000..717a3fffda --- /dev/null +++ b/tools/clang-tidy/test/clang-analyzer-cplusplus.Move.json @@ -0,0 +1 @@ +[["warning", "Moved-from object 'x' is moved", "clang-analyzer-cplusplus.Move"], {"reliability": "high"}]
\ No newline at end of file diff --git a/tools/clang-tidy/test/clang-analyzer-cplusplus.NewDelete.cpp b/tools/clang-tidy/test/clang-analyzer-cplusplus.NewDelete.cpp new file mode 100644 index 0000000000..d886d74989 --- /dev/null +++ b/tools/clang-tidy/test/clang-analyzer-cplusplus.NewDelete.cpp @@ -0,0 +1,50 @@ +// https://clang-analyzer.llvm.org/available_checks.html + +void use(int *p); + +void test_use_parameter_after_delete(int *p) +{ + delete p; + use(p); // warning: use after free +} + +class SomeClass { +public: + void f(); +}; + +void test_use_local_after_delete() +{ + SomeClass *c = new SomeClass; + delete c; + c->f(); // warning: use after free +} + +// XXX clang documentation says this should cause a warning but it doesn't! +void test_delete_alloca() +{ + int *p = (int *)__builtin_alloca(sizeof(int)); + delete p; // NO warning: deleting memory allocated by alloca +} + +void test_double_free() +{ + int *p = new int; + delete p; + delete p; // warning: attempt to free released +} + +void test_delete_local() +{ + int i; + delete &i; // warning: delete address of local +} + +// XXX clang documentation says this should cause a warning but it doesn't! +void test_delete_offset() +{ + int *p = new int[1]; + delete[] (++p); + // NO warning: argument to 'delete[]' is offset by 4 bytes + // from the start of memory allocated by 'new[]' +} diff --git a/tools/clang-tidy/test/clang-analyzer-cplusplus.NewDelete.json b/tools/clang-tidy/test/clang-analyzer-cplusplus.NewDelete.json new file mode 100644 index 0000000000..1ce0533da6 --- /dev/null +++ b/tools/clang-tidy/test/clang-analyzer-cplusplus.NewDelete.json @@ -0,0 +1 @@ +[["warning", "Use of memory after it is freed", "clang-analyzer-cplusplus.NewDelete"], ["warning", "Use of memory after it is freed", "clang-analyzer-cplusplus.NewDelete"], ["warning", "Attempt to free released memory", "clang-analyzer-cplusplus.NewDelete"], ["warning", "Argument to 'delete' is the address of the local variable 'i', which is not memory allocated by 'new'", "clang-analyzer-cplusplus.NewDelete"], {"reliability": "medium"}]
\ No newline at end of file diff --git a/tools/clang-tidy/test/clang-analyzer-cplusplus.NewDeleteLeaks.cpp b/tools/clang-tidy/test/clang-analyzer-cplusplus.NewDeleteLeaks.cpp new file mode 100644 index 0000000000..60772a30db --- /dev/null +++ b/tools/clang-tidy/test/clang-analyzer-cplusplus.NewDeleteLeaks.cpp @@ -0,0 +1,6 @@ +// https://clang-analyzer.llvm.org/available_checks.html + +void test() +{ + int *p = new int; +} // warning diff --git a/tools/clang-tidy/test/clang-analyzer-cplusplus.NewDeleteLeaks.json b/tools/clang-tidy/test/clang-analyzer-cplusplus.NewDeleteLeaks.json new file mode 100644 index 0000000000..eb30b102f6 --- /dev/null +++ b/tools/clang-tidy/test/clang-analyzer-cplusplus.NewDeleteLeaks.json @@ -0,0 +1 @@ +[["warning", "Potential leak of memory pointed to by 'p'", "clang-analyzer-cplusplus.NewDeleteLeaks"], {"reliability": "medium"}]
\ No newline at end of file diff --git a/tools/clang-tidy/test/clang-analyzer-deadcode.DeadStores.cpp b/tools/clang-tidy/test/clang-analyzer-deadcode.DeadStores.cpp new file mode 100644 index 0000000000..4e1c2c851d --- /dev/null +++ b/tools/clang-tidy/test/clang-analyzer-deadcode.DeadStores.cpp @@ -0,0 +1,6 @@ + +// clang-analyzer-deadcode.DeadStores +void test() { + int x; + x = 1; // warn +} diff --git a/tools/clang-tidy/test/clang-analyzer-deadcode.DeadStores.json b/tools/clang-tidy/test/clang-analyzer-deadcode.DeadStores.json new file mode 100644 index 0000000000..851599195c --- /dev/null +++ b/tools/clang-tidy/test/clang-analyzer-deadcode.DeadStores.json @@ -0,0 +1 @@ +[["warning", "Value stored to 'x' is never read", "clang-analyzer-deadcode.DeadStores"], {"reliability": "high"}]
\ No newline at end of file diff --git a/tools/clang-tidy/test/clang-analyzer-security.FloatLoopCounter.cpp b/tools/clang-tidy/test/clang-analyzer-security.FloatLoopCounter.cpp new file mode 100644 index 0000000000..60dcdad746 --- /dev/null +++ b/tools/clang-tidy/test/clang-analyzer-security.FloatLoopCounter.cpp @@ -0,0 +1,3 @@ +void test() { + for (float x = 0.1f; x <= 1.0f; x += 0.1f) {} +} diff --git a/tools/clang-tidy/test/clang-analyzer-security.FloatLoopCounter.json b/tools/clang-tidy/test/clang-analyzer-security.FloatLoopCounter.json new file mode 100644 index 0000000000..16f177cbfb --- /dev/null +++ b/tools/clang-tidy/test/clang-analyzer-security.FloatLoopCounter.json @@ -0,0 +1 @@ +[["warning", "Variable 'x' with floating point type 'float' should not be used as a loop counter", "clang-analyzer-security.FloatLoopCounter"], {"reliability": "high"}]
\ No newline at end of file diff --git a/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.UncheckedReturn.cpp b/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.UncheckedReturn.cpp new file mode 100644 index 0000000000..f1dede2d51 --- /dev/null +++ b/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.UncheckedReturn.cpp @@ -0,0 +1,5 @@ +#include "structures.h" + +void test() { + setuid(1); +} diff --git a/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.UncheckedReturn.json b/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.UncheckedReturn.json new file mode 100644 index 0000000000..dff8c498d2 --- /dev/null +++ b/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.UncheckedReturn.json @@ -0,0 +1 @@ +[["warning", "The return value from the call to 'setuid' is not checked. If an error occurs in 'setuid', the following code may execute with unexpected privileges", "clang-analyzer-security.insecureAPI.UncheckedReturn"], {"reliability": "low"}]
\ No newline at end of file diff --git a/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.bcmp.cpp b/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.bcmp.cpp new file mode 100644 index 0000000000..8821807518 --- /dev/null +++ b/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.bcmp.cpp @@ -0,0 +1,5 @@ +#include "structures.h" + +int test_bcmp(void *a, void *b, size_t n) { + return bcmp(a, b, n); +} diff --git a/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.bcmp.json b/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.bcmp.json new file mode 100644 index 0000000000..2b307e9047 --- /dev/null +++ b/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.bcmp.json @@ -0,0 +1 @@ +[["warning", "The bcmp() function is obsoleted by memcmp()", "clang-analyzer-security.insecureAPI.bcmp"], {"reliability": "high"}]
\ No newline at end of file diff --git a/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.bcopy.cpp b/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.bcopy.cpp new file mode 100644 index 0000000000..67df7d1638 --- /dev/null +++ b/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.bcopy.cpp @@ -0,0 +1,5 @@ +#include "structures.h" + +void test_bcopy(void *a, void *b, size_t n) { + bcopy(a, b, n); +} diff --git a/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.bcopy.json b/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.bcopy.json new file mode 100644 index 0000000000..9b5f58ba0f --- /dev/null +++ b/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.bcopy.json @@ -0,0 +1 @@ +[["warning", "The bcopy() function is obsoleted by memcpy() or memmove()", "clang-analyzer-security.insecureAPI.bcopy"], {"reliability": "high"}]
\ No newline at end of file diff --git a/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.bzero.cpp b/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.bzero.cpp new file mode 100644 index 0000000000..d3b5aa685f --- /dev/null +++ b/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.bzero.cpp @@ -0,0 +1,5 @@ +#include "structures.h" + +void test_bzero(void *a, size_t n) { + bzero(a, n); +} diff --git a/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.bzero.json b/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.bzero.json new file mode 100644 index 0000000000..17e8cc5bf1 --- /dev/null +++ b/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.bzero.json @@ -0,0 +1 @@ +[["warning", "The bzero() function is obsoleted by memset()", "clang-analyzer-security.insecureAPI.bzero"], {"reliability": "high"}]
\ No newline at end of file diff --git a/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.getpw.cpp b/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.getpw.cpp new file mode 100644 index 0000000000..c3da0b1970 --- /dev/null +++ b/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.getpw.cpp @@ -0,0 +1,6 @@ +#include "structures.h" + +void test() { + char buff[1024]; + getpw(2, buff); +} diff --git a/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.getpw.json b/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.getpw.json new file mode 100644 index 0000000000..737e626bdb --- /dev/null +++ b/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.getpw.json @@ -0,0 +1 @@ +[["warning", "The getpw() function is dangerous as it may overflow the provided buffer. It is obsoleted by getpwuid()", "clang-analyzer-security.insecureAPI.getpw"], {"reliability": "high"}]
\ No newline at end of file diff --git a/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.gets.cpp b/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.gets.cpp new file mode 100644 index 0000000000..f096c29de3 --- /dev/null +++ b/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.gets.cpp @@ -0,0 +1,6 @@ +#include <stdio.h> + +void test() { + char buff[1024]; + gets(buff); +} diff --git a/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.gets.json b/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.gets.json new file mode 100644 index 0000000000..0a61acf8da --- /dev/null +++ b/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.gets.json @@ -0,0 +1 @@ +"[[\"error\", \"use of undeclared identifier 'gets'\", \"clang-diagnostic-error\"]]"
\ No newline at end of file diff --git a/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.mkstemp.cpp b/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.mkstemp.cpp new file mode 100644 index 0000000000..904fc92ce6 --- /dev/null +++ b/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.mkstemp.cpp @@ -0,0 +1,5 @@ +#include "structures.h" + +void test() { + mkstemp("XX"); +} diff --git a/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.mkstemp.json b/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.mkstemp.json new file mode 100644 index 0000000000..5dd7c29e97 --- /dev/null +++ b/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.mkstemp.json @@ -0,0 +1 @@ +[["warning", "Call to 'mkstemp' should have at least 6 'X's in the format string to be secure (2 'X's seen)", "clang-analyzer-security.insecureAPI.mkstemp"], {"reliability": "high"}]
\ No newline at end of file diff --git a/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.mktemp.cpp b/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.mktemp.cpp new file mode 100644 index 0000000000..8bb511a7d7 --- /dev/null +++ b/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.mktemp.cpp @@ -0,0 +1,5 @@ +#include "structures.h" + +void test() { + char *x = mktemp("/tmp/zxcv"); +} diff --git a/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.mktemp.json b/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.mktemp.json new file mode 100644 index 0000000000..30f1d9d315 --- /dev/null +++ b/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.mktemp.json @@ -0,0 +1 @@ +[["warning", "Call to function 'mktemp' is insecure as it always creates or uses insecure temporary file. Use 'mkstemp' instead", "clang-analyzer-security.insecureAPI.mktemp"], {"reliability": "high"}]
\ No newline at end of file diff --git a/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.rand.cpp b/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.rand.cpp new file mode 100644 index 0000000000..2274127c50 --- /dev/null +++ b/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.rand.cpp @@ -0,0 +1,4 @@ +#include <stdlib.h> +void test() { + random(); +} diff --git a/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.rand.json b/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.rand.json new file mode 100644 index 0000000000..d10d93509a --- /dev/null +++ b/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.rand.json @@ -0,0 +1 @@ +"[[\"warning\", \"The 'random' function produces a sequence of values that an adversary may be able to predict. Use 'arc4random' instead\", \"clang-analyzer-security.insecureAPI.rand\"]]"
\ No newline at end of file diff --git a/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.strcpy.cpp b/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.strcpy.cpp new file mode 100644 index 0000000000..41713adb4e --- /dev/null +++ b/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.strcpy.cpp @@ -0,0 +1,7 @@ +#include <string.h> +void test() { + char x[4]; + char *y = "abcd"; + + strcpy(x, y); +} diff --git a/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.strcpy.json b/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.strcpy.json new file mode 100644 index 0000000000..ab01530b21 --- /dev/null +++ b/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.strcpy.json @@ -0,0 +1 @@ +"[[\"warning\", \"Call to function 'strcpy' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcpy'. CWE-119\", \"clang-analyzer-security.insecureAPI.strcpy\"], [\"note\", \"Call to function 'strcpy' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcpy'. CWE-119\", null]]"
\ No newline at end of file diff --git a/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.vfork.cpp b/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.vfork.cpp new file mode 100644 index 0000000000..619d986cf7 --- /dev/null +++ b/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.vfork.cpp @@ -0,0 +1,5 @@ +#include "structures.h" + +void test() { + vfork(); +} diff --git a/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.vfork.json b/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.vfork.json new file mode 100644 index 0000000000..251418737b --- /dev/null +++ b/tools/clang-tidy/test/clang-analyzer-security.insecureAPI.vfork.json @@ -0,0 +1 @@ +[["warning", "Call to function 'vfork' is insecure as it can lead to denial of service situations in the parent process. Replace calls to vfork with calls to the safer 'posix_spawn' function", "clang-analyzer-security.insecureAPI.vfork"], {"reliability": "medium"}]
\ No newline at end of file diff --git a/tools/clang-tidy/test/clang-analyzer-unix.Malloc.cpp b/tools/clang-tidy/test/clang-analyzer-unix.Malloc.cpp new file mode 100644 index 0000000000..a08422b336 --- /dev/null +++ b/tools/clang-tidy/test/clang-analyzer-unix.Malloc.cpp @@ -0,0 +1,37 @@ +// https://clang-analyzer.llvm.org/available_checks.html + +#include "structures.h" + +void test_malloc() +{ + int *p = (int*) malloc(1); + free(p); + free(p); // warning: attempt to free released memory +} + +void test_use_after_free() +{ + int *p = (int*) malloc(sizeof(int)); + free(p); + *p = 1; // warning: use after free +} + +void test_leak() +{ + int *p = (int*) malloc(1); + if (p) + return; // warning: memory is never released +} + +void test_free_local() +{ + int a[] = { 1 }; + free(a); // warning: argument is not allocated by malloc +} + +void test_free_offset() +{ + int *p = (int*) malloc(sizeof(char)); + p = p - 1; + free(p); // warning: argument to free() is offset by -4 bytes +} diff --git a/tools/clang-tidy/test/clang-analyzer-unix.Malloc.json b/tools/clang-tidy/test/clang-analyzer-unix.Malloc.json new file mode 100644 index 0000000000..c26363da01 --- /dev/null +++ b/tools/clang-tidy/test/clang-analyzer-unix.Malloc.json @@ -0,0 +1 @@ +[["warning", "Attempt to free released memory", "clang-analyzer-unix.Malloc"], ["warning", "Use of memory after it is freed", "clang-analyzer-unix.Malloc"], ["warning", "Potential leak of memory pointed to by 'p'", "clang-analyzer-unix.Malloc"], ["warning", "Argument to free() is the address of the local variable 'a', which is not memory allocated by malloc()", "clang-analyzer-unix.Malloc"], ["warning", "Argument to free() is offset by -4 bytes from the start of memory allocated by malloc()", "clang-analyzer-unix.Malloc"], {"reliability": "high"}]
\ No newline at end of file diff --git a/tools/clang-tidy/test/clang-analyzer-unix.cstring.BadSizeArg.cpp b/tools/clang-tidy/test/clang-analyzer-unix.cstring.BadSizeArg.cpp new file mode 100644 index 0000000000..124737c3f4 --- /dev/null +++ b/tools/clang-tidy/test/clang-analyzer-unix.cstring.BadSizeArg.cpp @@ -0,0 +1,9 @@ +// https://clang-analyzer.llvm.org/available_checks.html + +#include "structures.h" + +void test() +{ + char dest[3]; + strncat(dest, "***", sizeof(dest)); // warning : potential buffer overflow +} diff --git a/tools/clang-tidy/test/clang-analyzer-unix.cstring.BadSizeArg.json b/tools/clang-tidy/test/clang-analyzer-unix.cstring.BadSizeArg.json new file mode 100644 index 0000000000..756f3ed5e2 --- /dev/null +++ b/tools/clang-tidy/test/clang-analyzer-unix.cstring.BadSizeArg.json @@ -0,0 +1 @@ +[["warning", "Potential buffer overflow. Replace with 'sizeof(dest) - strlen(dest) - 1' or use a safer 'strlcat' API", "clang-analyzer-unix.cstring.BadSizeArg"], {"reliability": "high"}]
\ No newline at end of file diff --git a/tools/clang-tidy/test/clang-analyzer-unix.cstring.NullArg.cpp b/tools/clang-tidy/test/clang-analyzer-unix.cstring.NullArg.cpp new file mode 100644 index 0000000000..30cdaf6ce9 --- /dev/null +++ b/tools/clang-tidy/test/clang-analyzer-unix.cstring.NullArg.cpp @@ -0,0 +1,14 @@ +// https://clang-analyzer.llvm.org/available_checks.html + +#include "structures.h" + +int my_strlen(const char* s) +{ + return strlen(s); // warning +} + +int bad_caller() +{ + const char* s = nullptr; + return my_strlen(s); +} diff --git a/tools/clang-tidy/test/clang-analyzer-unix.cstring.NullArg.json b/tools/clang-tidy/test/clang-analyzer-unix.cstring.NullArg.json new file mode 100644 index 0000000000..ff9f49fed9 --- /dev/null +++ b/tools/clang-tidy/test/clang-analyzer-unix.cstring.NullArg.json @@ -0,0 +1 @@ +[["warning", "Null pointer passed as 1st argument to string length function", "clang-analyzer-unix.cstring.NullArg"], {"reliability": "high"}]
\ No newline at end of file diff --git a/tools/clang-tidy/test/cppcoreguidelines-narrowing-conversions.cpp b/tools/clang-tidy/test/cppcoreguidelines-narrowing-conversions.cpp new file mode 100644 index 0000000000..b10b0fa1c3 --- /dev/null +++ b/tools/clang-tidy/test/cppcoreguidelines-narrowing-conversions.cpp @@ -0,0 +1,4 @@ +class Foo { + int f; + void a_f(double val) { f = val;} +}; diff --git a/tools/clang-tidy/test/cppcoreguidelines-narrowing-conversions.json b/tools/clang-tidy/test/cppcoreguidelines-narrowing-conversions.json new file mode 100644 index 0000000000..8a06366c99 --- /dev/null +++ b/tools/clang-tidy/test/cppcoreguidelines-narrowing-conversions.json @@ -0,0 +1 @@ +[["warning", "narrowing conversion from 'double' to 'int'", "cppcoreguidelines-narrowing-conversions"], {"reliability": "high"}]
\ No newline at end of file diff --git a/tools/clang-tidy/test/cppcoreguidelines-pro-type-member-init.cpp b/tools/clang-tidy/test/cppcoreguidelines-pro-type-member-init.cpp new file mode 100644 index 0000000000..be331829f3 --- /dev/null +++ b/tools/clang-tidy/test/cppcoreguidelines-pro-type-member-init.cpp @@ -0,0 +1,7 @@ +struct Foo final { + int x; +}; + +void foo() { + Foo y; +} diff --git a/tools/clang-tidy/test/cppcoreguidelines-pro-type-member-init.json b/tools/clang-tidy/test/cppcoreguidelines-pro-type-member-init.json new file mode 100644 index 0000000000..06c7e21046 --- /dev/null +++ b/tools/clang-tidy/test/cppcoreguidelines-pro-type-member-init.json @@ -0,0 +1 @@ +[["warning", "uninitialized record type: 'y'", "cppcoreguidelines-pro-type-member-init"], {"reliability": "medium"}]
\ No newline at end of file diff --git a/tools/clang-tidy/test/misc-non-copyable-objects.cpp b/tools/clang-tidy/test/misc-non-copyable-objects.cpp new file mode 100644 index 0000000000..2f9060a818 --- /dev/null +++ b/tools/clang-tidy/test/misc-non-copyable-objects.cpp @@ -0,0 +1,5 @@ +namespace std { +typedef struct FILE {} FILE; +} + +void g(std::FILE f); diff --git a/tools/clang-tidy/test/misc-non-copyable-objects.json b/tools/clang-tidy/test/misc-non-copyable-objects.json new file mode 100644 index 0000000000..5352f69a3d --- /dev/null +++ b/tools/clang-tidy/test/misc-non-copyable-objects.json @@ -0,0 +1 @@ +[["warning", "'f' declared as type 'FILE', which is unsafe to copy; did you mean 'FILE *'?", "misc-non-copyable-objects"], {"reliability": "high"}]
\ No newline at end of file diff --git a/tools/clang-tidy/test/misc-redundant-expression.cpp b/tools/clang-tidy/test/misc-redundant-expression.cpp new file mode 100644 index 0000000000..0ccc9c55f7 --- /dev/null +++ b/tools/clang-tidy/test/misc-redundant-expression.cpp @@ -0,0 +1,3 @@ +int TestSimpleEquivalent(int X, int Y) { + if (X - X) return 1; +} diff --git a/tools/clang-tidy/test/misc-redundant-expression.json b/tools/clang-tidy/test/misc-redundant-expression.json new file mode 100644 index 0000000000..f48dd67510 --- /dev/null +++ b/tools/clang-tidy/test/misc-redundant-expression.json @@ -0,0 +1 @@ +[["warning", "both sides of operator are equivalent", "misc-redundant-expression"], {"reliability": "medium"}]
\ No newline at end of file diff --git a/tools/clang-tidy/test/misc-unused-alias-decls.cpp b/tools/clang-tidy/test/misc-unused-alias-decls.cpp new file mode 100644 index 0000000000..1bbaa2db0a --- /dev/null +++ b/tools/clang-tidy/test/misc-unused-alias-decls.cpp @@ -0,0 +1,18 @@ +// https://clang.llvm.org/extra/clang-tidy/checks/misc-unused-alias-decls.html + +namespace n1 { + namespace n2 { + namespace n3 { + int qux = 42; + } + } +} + +namespace n1_unused = ::n1; // WARNING +namespace n12_unused = n1::n2; // WARNING +namespace n123 = n1::n2::n3; // OK + +int test() +{ + return n123::qux; +} diff --git a/tools/clang-tidy/test/misc-unused-alias-decls.json b/tools/clang-tidy/test/misc-unused-alias-decls.json new file mode 100644 index 0000000000..b577a4267b --- /dev/null +++ b/tools/clang-tidy/test/misc-unused-alias-decls.json @@ -0,0 +1 @@ +[["warning", "namespace alias decl 'n1_unused' is unused", "misc-unused-alias-decls"], ["warning", "namespace alias decl 'n12_unused' is unused", "misc-unused-alias-decls"], {"reliability": "high"}]
\ No newline at end of file diff --git a/tools/clang-tidy/test/misc-unused-using-decls.cpp b/tools/clang-tidy/test/misc-unused-using-decls.cpp new file mode 100644 index 0000000000..6564711aba --- /dev/null +++ b/tools/clang-tidy/test/misc-unused-using-decls.cpp @@ -0,0 +1,4 @@ + +// misc-unused-using-decls +namespace n { class C; } +using n::C; diff --git a/tools/clang-tidy/test/misc-unused-using-decls.json b/tools/clang-tidy/test/misc-unused-using-decls.json new file mode 100644 index 0000000000..aa28422a71 --- /dev/null +++ b/tools/clang-tidy/test/misc-unused-using-decls.json @@ -0,0 +1 @@ +[["warning", "using decl 'C' is unused", "misc-unused-using-decls"], {"reliability": "high"}]
\ No newline at end of file diff --git a/tools/clang-tidy/test/modernize-avoid-bind.cpp b/tools/clang-tidy/test/modernize-avoid-bind.cpp new file mode 100644 index 0000000000..c46fb31cd5 --- /dev/null +++ b/tools/clang-tidy/test/modernize-avoid-bind.cpp @@ -0,0 +1,6 @@ +#include "structures.h" + +int add(int x, int y) { return x + y; } +void f_bind() { + auto clj = std::bind(add, 2, 2); +} diff --git a/tools/clang-tidy/test/modernize-avoid-bind.json b/tools/clang-tidy/test/modernize-avoid-bind.json new file mode 100644 index 0000000000..8afa235b8d --- /dev/null +++ b/tools/clang-tidy/test/modernize-avoid-bind.json @@ -0,0 +1 @@ +[["warning", "prefer a lambda to std::bind", "modernize-avoid-bind"], {"reliability": "medium"}]
\ No newline at end of file diff --git a/tools/clang-tidy/test/modernize-concat-nested-namespaces.cpp b/tools/clang-tidy/test/modernize-concat-nested-namespaces.cpp new file mode 100644 index 0000000000..0ff35d0e07 --- /dev/null +++ b/tools/clang-tidy/test/modernize-concat-nested-namespaces.cpp @@ -0,0 +1,5 @@ +namespace mozilla { +namespace dom { +void foo(); +} +} diff --git a/tools/clang-tidy/test/modernize-concat-nested-namespaces.json b/tools/clang-tidy/test/modernize-concat-nested-namespaces.json new file mode 100644 index 0000000000..be284d32d3 --- /dev/null +++ b/tools/clang-tidy/test/modernize-concat-nested-namespaces.json @@ -0,0 +1 @@ +[["warning", "nested namespaces can be concatenated", "modernize-concat-nested-namespaces"], {"reliability": "high"}] diff --git a/tools/clang-tidy/test/modernize-deprecated-ios-base-aliases.cpp b/tools/clang-tidy/test/modernize-deprecated-ios-base-aliases.cpp new file mode 100644 index 0000000000..288fac8483 --- /dev/null +++ b/tools/clang-tidy/test/modernize-deprecated-ios-base-aliases.cpp @@ -0,0 +1,18 @@ +namespace std { +class ios_base { +public: + typedef int io_state; + typedef int open_mode; + typedef int seek_dir; + + typedef int streampos; + typedef int streamoff; +}; + +template <class CharT> +class basic_ios : public ios_base { +}; +} // namespace std + +// Test function return values (declaration) +std::ios_base::io_state f_5(); diff --git a/tools/clang-tidy/test/modernize-deprecated-ios-base-aliases.json b/tools/clang-tidy/test/modernize-deprecated-ios-base-aliases.json new file mode 100644 index 0000000000..87c682242c --- /dev/null +++ b/tools/clang-tidy/test/modernize-deprecated-ios-base-aliases.json @@ -0,0 +1 @@ +[["warning", "'std::ios_base::io_state' is deprecated; use 'std::ios_base::iostate' instead", "modernize-deprecated-ios-base-aliases"], {"reliability": "high"}]
\ No newline at end of file diff --git a/tools/clang-tidy/test/modernize-loop-convert.cpp b/tools/clang-tidy/test/modernize-loop-convert.cpp new file mode 100644 index 0000000000..2205846c7e --- /dev/null +++ b/tools/clang-tidy/test/modernize-loop-convert.cpp @@ -0,0 +1,7 @@ +int arr[6] = {1, 2, 3, 4, 5, 6}; + +void bar(void) { + for (int i = 0; i < 6; ++i) { + (void)arr[i]; + } +} diff --git a/tools/clang-tidy/test/modernize-loop-convert.json b/tools/clang-tidy/test/modernize-loop-convert.json new file mode 100644 index 0000000000..34d69ab54d --- /dev/null +++ b/tools/clang-tidy/test/modernize-loop-convert.json @@ -0,0 +1 @@ +[["warning", "use range-based for loop instead", "modernize-loop-convert"], {"reliability": "high"}]
\ No newline at end of file diff --git a/tools/clang-tidy/test/modernize-raw-string-literal.cpp b/tools/clang-tidy/test/modernize-raw-string-literal.cpp new file mode 100644 index 0000000000..d120aad9bf --- /dev/null +++ b/tools/clang-tidy/test/modernize-raw-string-literal.cpp @@ -0,0 +1 @@ +char const *const ManyQuotes("quotes:\'\'\'\'"); diff --git a/tools/clang-tidy/test/modernize-raw-string-literal.json b/tools/clang-tidy/test/modernize-raw-string-literal.json new file mode 100644 index 0000000000..5ff75a2ba5 --- /dev/null +++ b/tools/clang-tidy/test/modernize-raw-string-literal.json @@ -0,0 +1 @@ +[["warning", "escaped string literal can be written as a raw string literal", "modernize-raw-string-literal"], {"reliability": "high"}]
\ No newline at end of file diff --git a/tools/clang-tidy/test/modernize-redundant-void-arg.cpp b/tools/clang-tidy/test/modernize-redundant-void-arg.cpp new file mode 100644 index 0000000000..078e0e13ca --- /dev/null +++ b/tools/clang-tidy/test/modernize-redundant-void-arg.cpp @@ -0,0 +1,5 @@ +// modernize-redundant-void-arg + +int foo(void) { + return 0; +} diff --git a/tools/clang-tidy/test/modernize-redundant-void-arg.json b/tools/clang-tidy/test/modernize-redundant-void-arg.json new file mode 100644 index 0000000000..5dd0115cc9 --- /dev/null +++ b/tools/clang-tidy/test/modernize-redundant-void-arg.json @@ -0,0 +1 @@ +"[[\"warning\", \"redundant void argument list in function definition\", \"modernize-redundant-void-arg\"]]"
\ No newline at end of file diff --git a/tools/clang-tidy/test/modernize-shrink-to-fit.cpp b/tools/clang-tidy/test/modernize-shrink-to-fit.cpp new file mode 100644 index 0000000000..c545a517a3 --- /dev/null +++ b/tools/clang-tidy/test/modernize-shrink-to-fit.cpp @@ -0,0 +1,10 @@ +#include "structures.h" + +void f() { + std::vector<int> v; + + std::vector<int>(v).swap(v); + + std::vector<int> &vref = v; + std::vector<int>(vref).swap(vref); +} diff --git a/tools/clang-tidy/test/modernize-shrink-to-fit.json b/tools/clang-tidy/test/modernize-shrink-to-fit.json new file mode 100644 index 0000000000..55ebf37f06 --- /dev/null +++ b/tools/clang-tidy/test/modernize-shrink-to-fit.json @@ -0,0 +1 @@ +[["warning", "the shrink_to_fit method should be used to reduce the capacity of a shrinkable container", "modernize-shrink-to-fit"], ["warning", "the shrink_to_fit method should be used to reduce the capacity of a shrinkable container", "modernize-shrink-to-fit"], {"reliability": "high"}]
\ No newline at end of file diff --git a/tools/clang-tidy/test/modernize-use-auto.cpp b/tools/clang-tidy/test/modernize-use-auto.cpp new file mode 100644 index 0000000000..ba54d0cb8a --- /dev/null +++ b/tools/clang-tidy/test/modernize-use-auto.cpp @@ -0,0 +1,11 @@ +#include <vector> + +void func() { + int val = 42; + std::vector<int> my_container; + for (std::vector<int>::iterator I = my_container.begin(), + E = my_container.end(); + I != E; + ++I) { + } +} diff --git a/tools/clang-tidy/test/modernize-use-auto.json b/tools/clang-tidy/test/modernize-use-auto.json new file mode 100644 index 0000000000..7b3f9896ea --- /dev/null +++ b/tools/clang-tidy/test/modernize-use-auto.json @@ -0,0 +1 @@ +"[[\"warning\", \"use auto when declaring iterators\", \"modernize-use-auto\"]]"
\ No newline at end of file diff --git a/tools/clang-tidy/test/modernize-use-bool-literals.cpp b/tools/clang-tidy/test/modernize-use-bool-literals.cpp new file mode 100644 index 0000000000..58b7ec8f29 --- /dev/null +++ b/tools/clang-tidy/test/modernize-use-bool-literals.cpp @@ -0,0 +1,5 @@ +void foo() { + bool p = 1; + bool f = static_cast<bool>(1); + bool x = p ? 1 : 0; +} diff --git a/tools/clang-tidy/test/modernize-use-bool-literals.json b/tools/clang-tidy/test/modernize-use-bool-literals.json new file mode 100644 index 0000000000..ee869b51d6 --- /dev/null +++ b/tools/clang-tidy/test/modernize-use-bool-literals.json @@ -0,0 +1 @@ +[["warning", "converting integer literal to bool, use bool literal instead", "modernize-use-bool-literals"], ["warning", "converting integer literal to bool, use bool literal instead", "modernize-use-bool-literals"], ["warning", "converting integer literal to bool, use bool literal instead", "modernize-use-bool-literals"], ["warning", "converting integer literal to bool, use bool literal instead", "modernize-use-bool-literals"], {"reliability": "high"}]
\ No newline at end of file diff --git a/tools/clang-tidy/test/modernize-use-equals-default.cpp b/tools/clang-tidy/test/modernize-use-equals-default.cpp new file mode 100644 index 0000000000..ea5f71d93a --- /dev/null +++ b/tools/clang-tidy/test/modernize-use-equals-default.cpp @@ -0,0 +1,6 @@ + +class IL { +public: + IL() {} + ~IL() {} +}; diff --git a/tools/clang-tidy/test/modernize-use-equals-default.json b/tools/clang-tidy/test/modernize-use-equals-default.json new file mode 100644 index 0000000000..fb103bbad1 --- /dev/null +++ b/tools/clang-tidy/test/modernize-use-equals-default.json @@ -0,0 +1 @@ +[["warning", "use '= default' to define a trivial default constructor", "modernize-use-equals-default"], ["warning", "use '= default' to define a trivial destructor", "modernize-use-equals-default"], {"reliability": "high"}]
\ No newline at end of file diff --git a/tools/clang-tidy/test/modernize-use-equals-delete.cpp b/tools/clang-tidy/test/modernize-use-equals-delete.cpp new file mode 100644 index 0000000000..f08848c0a6 --- /dev/null +++ b/tools/clang-tidy/test/modernize-use-equals-delete.cpp @@ -0,0 +1,7 @@ +struct PositivePrivate { +private: + PositivePrivate(); + PositivePrivate(const PositivePrivate &); + PositivePrivate &operator=(PositivePrivate &&); + ~PositivePrivate(); +}; diff --git a/tools/clang-tidy/test/modernize-use-equals-delete.json b/tools/clang-tidy/test/modernize-use-equals-delete.json new file mode 100644 index 0000000000..d8634daa0f --- /dev/null +++ b/tools/clang-tidy/test/modernize-use-equals-delete.json @@ -0,0 +1 @@ +[["warning", "use '= delete' to prohibit calling of a special member function", "modernize-use-equals-delete"], ["warning", "use '= delete' to prohibit calling of a special member function", "modernize-use-equals-delete"], ["warning", "use '= delete' to prohibit calling of a special member function", "modernize-use-equals-delete"], ["warning", "use '= delete' to prohibit calling of a special member function", "modernize-use-equals-delete"], {"reliability": "high"}]
\ No newline at end of file diff --git a/tools/clang-tidy/test/modernize-use-nullptr.cpp b/tools/clang-tidy/test/modernize-use-nullptr.cpp new file mode 100644 index 0000000000..4b8b3ee3c0 --- /dev/null +++ b/tools/clang-tidy/test/modernize-use-nullptr.cpp @@ -0,0 +1,5 @@ +#define NULL 0 +void f(void) { + char *str = NULL; // ok + (void)str; +} diff --git a/tools/clang-tidy/test/modernize-use-nullptr.json b/tools/clang-tidy/test/modernize-use-nullptr.json new file mode 100644 index 0000000000..148da8b56e --- /dev/null +++ b/tools/clang-tidy/test/modernize-use-nullptr.json @@ -0,0 +1 @@ +[["warning", "use nullptr", "modernize-use-nullptr"], {"reliability": "high"}]
\ No newline at end of file diff --git a/tools/clang-tidy/test/modernize-use-override.cpp b/tools/clang-tidy/test/modernize-use-override.cpp new file mode 100644 index 0000000000..1cbec3868c --- /dev/null +++ b/tools/clang-tidy/test/modernize-use-override.cpp @@ -0,0 +1,8 @@ +class Base { +public: + virtual void foo() = 0; +}; + +class Deriv : public Base { + void foo(); +}; diff --git a/tools/clang-tidy/test/modernize-use-override.json b/tools/clang-tidy/test/modernize-use-override.json new file mode 100644 index 0000000000..1feb99e6d7 --- /dev/null +++ b/tools/clang-tidy/test/modernize-use-override.json @@ -0,0 +1 @@ +"[[\"warning\", \"annotate this function with 'override' or (rarely) 'final'\", \"modernize-use-override\"]]"
\ No newline at end of file diff --git a/tools/clang-tidy/test/modernize-use-using.cpp b/tools/clang-tidy/test/modernize-use-using.cpp new file mode 100644 index 0000000000..0e7b73222c --- /dev/null +++ b/tools/clang-tidy/test/modernize-use-using.cpp @@ -0,0 +1,5 @@ +template <typename T> +class Test { + typedef typename T::iterator Iter; +}; +typedef int Type; diff --git a/tools/clang-tidy/test/modernize-use-using.json b/tools/clang-tidy/test/modernize-use-using.json new file mode 100644 index 0000000000..ab104d060a --- /dev/null +++ b/tools/clang-tidy/test/modernize-use-using.json @@ -0,0 +1 @@ +[["warning", "use 'using' instead of 'typedef'", "modernize-use-using"], ["warning", "use 'using' instead of 'typedef'", "modernize-use-using"], {"reliability": "high"}]
\ No newline at end of file diff --git a/tools/clang-tidy/test/performance-faster-string-find.cpp b/tools/clang-tidy/test/performance-faster-string-find.cpp new file mode 100644 index 0000000000..d7ac3d0c3c --- /dev/null +++ b/tools/clang-tidy/test/performance-faster-string-find.cpp @@ -0,0 +1,6 @@ +#include "structures.h" + +void foo() { + std::string str; + str.find("A"); +} diff --git a/tools/clang-tidy/test/performance-faster-string-find.json b/tools/clang-tidy/test/performance-faster-string-find.json new file mode 100644 index 0000000000..bcbbba0d54 --- /dev/null +++ b/tools/clang-tidy/test/performance-faster-string-find.json @@ -0,0 +1 @@ +[["warning", "'find' called with a string literal consisting of a single character; consider using the more effective overload accepting a character", "performance-faster-string-find"], {"reliability": "high"}]
\ No newline at end of file diff --git a/tools/clang-tidy/test/performance-for-range-copy.cpp b/tools/clang-tidy/test/performance-for-range-copy.cpp new file mode 100644 index 0000000000..264dd42896 --- /dev/null +++ b/tools/clang-tidy/test/performance-for-range-copy.cpp @@ -0,0 +1,30 @@ +template <typename T> +struct Iterator { + void operator++() {} + const T& operator*() { + static T* TT = new T(); + return *TT; + } + bool operator!=(const Iterator &) { return false; } + typedef const T& const_reference; +}; +template <typename T> +struct View { + T begin() { return T(); } + T begin() const { return T(); } + T end() { return T(); } + T end() const { return T(); } + typedef typename T::const_reference const_reference; +}; + +struct S { + S(); + S(const S &); + ~S(); + S &operator=(const S &); +}; + +void negativeConstReference() { + for (const S S1 : View<Iterator<S>>()) { + } +} diff --git a/tools/clang-tidy/test/performance-for-range-copy.json b/tools/clang-tidy/test/performance-for-range-copy.json new file mode 100644 index 0000000000..7407740716 --- /dev/null +++ b/tools/clang-tidy/test/performance-for-range-copy.json @@ -0,0 +1 @@ +[["warning", "the loop variable's type is not a reference type; this creates a copy in each iteration; consider making this a reference", "performance-for-range-copy"], {"reliability": "high"}]
\ No newline at end of file diff --git a/tools/clang-tidy/test/performance-implicit-conversion-in-loop.cpp b/tools/clang-tidy/test/performance-implicit-conversion-in-loop.cpp new file mode 100644 index 0000000000..75ed510f3f --- /dev/null +++ b/tools/clang-tidy/test/performance-implicit-conversion-in-loop.cpp @@ -0,0 +1,43 @@ +// Iterator returning by value. +template <typename T> +struct Iterator { + void operator++(); + T operator*(); + bool operator!=(const Iterator& other); +}; + +// The template argument is an iterator type, and a view is an object you can +// run a for loop on. +template <typename T> +struct View { + T begin(); + T end(); +}; + +// With this class, the implicit conversion is a call to the (implicit) +// constructor of the class. +template <typename T> +class ImplicitWrapper { + public: + // Implicit! + ImplicitWrapper(const T& t); +}; + +template <typename T> +class OperatorWrapper { + public: + OperatorWrapper() = delete; +}; + +struct SimpleClass { + int foo; + operator OperatorWrapper<SimpleClass>(); +}; + +typedef View<Iterator<SimpleClass>> SimpleView; + +void ImplicitSimpleClassIterator() { + for (const ImplicitWrapper<SimpleClass>& foo : SimpleView()) {} + for (const ImplicitWrapper<SimpleClass> foo : SimpleView()) {} + for (ImplicitWrapper<SimpleClass> foo : SimpleView()) {} +} diff --git a/tools/clang-tidy/test/performance-implicit-conversion-in-loop.json b/tools/clang-tidy/test/performance-implicit-conversion-in-loop.json new file mode 100644 index 0000000000..f6f6fc8f16 --- /dev/null +++ b/tools/clang-tidy/test/performance-implicit-conversion-in-loop.json @@ -0,0 +1 @@ +[["warning", "the type of the loop variable 'foo' is different from the one returned by the iterator and generates an implicit conversion; you can either change the type to the matching one ('const SimpleClass &' but 'const auto&' is always a valid option) or remove the reference to make it explicit that you are creating a new value", "performance-implicit-conversion-in-loop"], {"reliability": "high"}]
\ No newline at end of file diff --git a/tools/clang-tidy/test/performance-inefficient-algorithm.cpp b/tools/clang-tidy/test/performance-inefficient-algorithm.cpp new file mode 100644 index 0000000000..b508260dbd --- /dev/null +++ b/tools/clang-tidy/test/performance-inefficient-algorithm.cpp @@ -0,0 +1,30 @@ +namespace std { +template <typename T> struct less { + bool operator()(const T &lhs, const T &rhs) { return lhs < rhs; } +}; + +template <typename T> struct greater { + bool operator()(const T &lhs, const T &rhs) { return lhs > rhs; } +}; + +struct iterator_type {}; + +template <typename K, typename Cmp = less<K>> struct set { + typedef iterator_type iterator; + iterator find(const K &k); + unsigned count(const K &k); + + iterator begin(); + iterator end(); + iterator begin() const; + iterator end() const; +}; + +template <typename FwIt, typename K> +FwIt find(FwIt, FwIt end, const K &) { return end; } +} + +template <typename T> void f(const T &t) { + std::set<int> s; + find(s.begin(), s.end(), 46); +} diff --git a/tools/clang-tidy/test/performance-inefficient-algorithm.json b/tools/clang-tidy/test/performance-inefficient-algorithm.json new file mode 100644 index 0000000000..46c5870f2e --- /dev/null +++ b/tools/clang-tidy/test/performance-inefficient-algorithm.json @@ -0,0 +1 @@ +[["warning", "this STL algorithm call should be replaced with a container method", "performance-inefficient-algorithm"], {"reliability": "high"}]
\ No newline at end of file diff --git a/tools/clang-tidy/test/performance-inefficient-string-concatenation.cpp b/tools/clang-tidy/test/performance-inefficient-string-concatenation.cpp new file mode 100644 index 0000000000..5a5860f215 --- /dev/null +++ b/tools/clang-tidy/test/performance-inefficient-string-concatenation.cpp @@ -0,0 +1,13 @@ +#include "structures.h" + +extern void fstring(std::string); + +void foo() { + std::string mystr1, mystr2; + auto myautostr1 = mystr1; + auto myautostr2 = mystr2; + + for (int i = 0; i < 10; ++i) { + fstring(mystr1 + mystr2 + mystr1); + } +} diff --git a/tools/clang-tidy/test/performance-inefficient-string-concatenation.json b/tools/clang-tidy/test/performance-inefficient-string-concatenation.json new file mode 100644 index 0000000000..7ef02e061a --- /dev/null +++ b/tools/clang-tidy/test/performance-inefficient-string-concatenation.json @@ -0,0 +1 @@ +[["warning", "string concatenation results in allocation of unnecessary temporary strings; consider using 'operator+=' or 'string::append()' instead", "performance-inefficient-string-concatenation"], {"reliability": "high"}]
\ No newline at end of file diff --git a/tools/clang-tidy/test/performance-inefficient-vector-operation.cpp b/tools/clang-tidy/test/performance-inefficient-vector-operation.cpp new file mode 100644 index 0000000000..4f0e143aa2 --- /dev/null +++ b/tools/clang-tidy/test/performance-inefficient-vector-operation.cpp @@ -0,0 +1,10 @@ +#include "structures.h" + +void foo() +{ + std::vector<int> v; + int n = 100; + for (int i = 0; i < n; ++i) { + v.push_back(n); + } +} diff --git a/tools/clang-tidy/test/performance-inefficient-vector-operation.json b/tools/clang-tidy/test/performance-inefficient-vector-operation.json new file mode 100644 index 0000000000..a8a0ffe748 --- /dev/null +++ b/tools/clang-tidy/test/performance-inefficient-vector-operation.json @@ -0,0 +1 @@ +[["warning", "'push_back' is called inside a loop; consider pre-allocating the container capacity before the loop", "performance-inefficient-vector-operation"], {"reliability": "high"}]
\ No newline at end of file diff --git a/tools/clang-tidy/test/performance-move-const-arg.cpp b/tools/clang-tidy/test/performance-move-const-arg.cpp new file mode 100644 index 0000000000..39f1ce06ec --- /dev/null +++ b/tools/clang-tidy/test/performance-move-const-arg.cpp @@ -0,0 +1,33 @@ +namespace std { +template <typename _Tp> +struct remove_reference { + typedef _Tp type; +}; + +template <typename _Tp> +constexpr typename std::remove_reference<_Tp>::type &&move(_Tp &&__t) { + return static_cast<typename std::remove_reference<_Tp>::type &&>(__t); +} +} // namespace std + +struct TriviallyCopyable { + int i; +}; + +class A { +public: + A() {} + A(const A &rhs) {} + A(A &&rhs) {} +}; + +void f(TriviallyCopyable) {} + +void g() { + TriviallyCopyable obj; + f(std::move(obj)); +} + +A f5(const A x5) { + return std::move(x5); +} diff --git a/tools/clang-tidy/test/performance-move-const-arg.json b/tools/clang-tidy/test/performance-move-const-arg.json new file mode 100644 index 0000000000..b41675ffec --- /dev/null +++ b/tools/clang-tidy/test/performance-move-const-arg.json @@ -0,0 +1 @@ +[["warning", "std::move of the const variable 'x5' has no effect; remove std::move() or make the variable non-const", "performance-move-const-arg"], {"reliability": "high"}]
\ No newline at end of file diff --git a/tools/clang-tidy/test/performance-move-constructor-init.cpp b/tools/clang-tidy/test/performance-move-constructor-init.cpp new file mode 100644 index 0000000000..243b399e95 --- /dev/null +++ b/tools/clang-tidy/test/performance-move-constructor-init.cpp @@ -0,0 +1,11 @@ +struct B { + B() {} + B(const B&) {} + B(B &&) {} +}; + +struct D : B { + D() : B() {} + D(const D &RHS) : B(RHS) {} + D(D &&RHS) : B(RHS) {} +}; diff --git a/tools/clang-tidy/test/performance-move-constructor-init.json b/tools/clang-tidy/test/performance-move-constructor-init.json new file mode 100644 index 0000000000..46f4b38aff --- /dev/null +++ b/tools/clang-tidy/test/performance-move-constructor-init.json @@ -0,0 +1 @@ +[["warning", "move constructor initializes base class by calling a copy constructor", "performance-move-constructor-init"], {"reliability": "high"}]
\ No newline at end of file diff --git a/tools/clang-tidy/test/performance-noexcept-move-constructor.cpp b/tools/clang-tidy/test/performance-noexcept-move-constructor.cpp new file mode 100644 index 0000000000..8b4900b00d --- /dev/null +++ b/tools/clang-tidy/test/performance-noexcept-move-constructor.cpp @@ -0,0 +1,4 @@ +class A { + A(A &&); + A &operator=(A &&); +}; diff --git a/tools/clang-tidy/test/performance-noexcept-move-constructor.json b/tools/clang-tidy/test/performance-noexcept-move-constructor.json new file mode 100644 index 0000000000..7e2a4e1b3d --- /dev/null +++ b/tools/clang-tidy/test/performance-noexcept-move-constructor.json @@ -0,0 +1 @@ +[["warning", "move constructors should be marked noexcept", "performance-noexcept-move-constructor"], ["warning", "move assignment operators should be marked noexcept", "performance-noexcept-move-constructor"], {"reliability": "high"}]
\ No newline at end of file diff --git a/tools/clang-tidy/test/performance-type-promotion-in-math-fn.cpp b/tools/clang-tidy/test/performance-type-promotion-in-math-fn.cpp new file mode 100644 index 0000000000..9a6fcf9848 --- /dev/null +++ b/tools/clang-tidy/test/performance-type-promotion-in-math-fn.cpp @@ -0,0 +1,7 @@ +double acos(double); + +void check_all_fns() +{ + float a; + acos(a); +} diff --git a/tools/clang-tidy/test/performance-type-promotion-in-math-fn.json b/tools/clang-tidy/test/performance-type-promotion-in-math-fn.json new file mode 100644 index 0000000000..4751f5c7c7 --- /dev/null +++ b/tools/clang-tidy/test/performance-type-promotion-in-math-fn.json @@ -0,0 +1 @@ +[["warning", "call to 'acos' promotes float to double", "performance-type-promotion-in-math-fn"], {"reliability": "high"}]
\ No newline at end of file diff --git a/tools/clang-tidy/test/performance-unnecessary-copy-initialization.cpp b/tools/clang-tidy/test/performance-unnecessary-copy-initialization.cpp new file mode 100644 index 0000000000..ca0f591a3e --- /dev/null +++ b/tools/clang-tidy/test/performance-unnecessary-copy-initialization.cpp @@ -0,0 +1,7 @@ +#include "structures.h" + +extern const std::string& constReference(); + +void foo() { + const std::string UnnecessaryCopy = constReference(); +} diff --git a/tools/clang-tidy/test/performance-unnecessary-copy-initialization.json b/tools/clang-tidy/test/performance-unnecessary-copy-initialization.json new file mode 100644 index 0000000000..4f2f033b40 --- /dev/null +++ b/tools/clang-tidy/test/performance-unnecessary-copy-initialization.json @@ -0,0 +1 @@ +[["warning", "the const qualified variable 'UnnecessaryCopy' is copy-constructed from a const reference; consider making it a const reference", "performance-unnecessary-copy-initialization"], {"reliability": "high"}]
\ No newline at end of file diff --git a/tools/clang-tidy/test/performance-unnecessary-value-param.cpp b/tools/clang-tidy/test/performance-unnecessary-value-param.cpp new file mode 100644 index 0000000000..ed5f36f7fa --- /dev/null +++ b/tools/clang-tidy/test/performance-unnecessary-value-param.cpp @@ -0,0 +1,4 @@ +#include "structures.h" + +void f(const std::string Value) { +} diff --git a/tools/clang-tidy/test/performance-unnecessary-value-param.json b/tools/clang-tidy/test/performance-unnecessary-value-param.json new file mode 100644 index 0000000000..6fee73dbd5 --- /dev/null +++ b/tools/clang-tidy/test/performance-unnecessary-value-param.json @@ -0,0 +1 @@ +[["warning", "the const qualified parameter 'Value' is copied for each invocation; consider making it a reference", "performance-unnecessary-value-param"], {"reliability": "high"}]
\ No newline at end of file diff --git a/tools/clang-tidy/test/readability-braces-around-statements.cpp b/tools/clang-tidy/test/readability-braces-around-statements.cpp new file mode 100644 index 0000000000..2a08b51bc9 --- /dev/null +++ b/tools/clang-tidy/test/readability-braces-around-statements.cpp @@ -0,0 +1,25 @@ + +void do_something(const char *) {} + +bool cond(const char *) { + return false; +} + +void test() { +if (cond("if0") /*comment*/) do_something("same-line"); +} + +void foo() { +if (1) while (2) if (3) for (;;) do ; while(false) /**/;/**/ +} + +void f() {} + +void foo2() { + constexpr bool a = true; + if constexpr (a) { + f(); + } else { + f(); + } +} diff --git a/tools/clang-tidy/test/readability-braces-around-statements.json b/tools/clang-tidy/test/readability-braces-around-statements.json new file mode 100644 index 0000000000..196e10487f --- /dev/null +++ b/tools/clang-tidy/test/readability-braces-around-statements.json @@ -0,0 +1 @@ +[["warning", "statement should be inside braces", "readability-braces-around-statements"], ["warning", "statement should be inside braces", "readability-braces-around-statements"], ["warning", "statement should be inside braces", "readability-braces-around-statements"], ["warning", "statement should be inside braces", "readability-braces-around-statements"], ["warning", "statement should be inside braces", "readability-braces-around-statements"], ["warning", "statement should be inside braces", "readability-braces-around-statements"], {"reliability": "high"}]
\ No newline at end of file diff --git a/tools/clang-tidy/test/readability-const-return-type.cpp b/tools/clang-tidy/test/readability-const-return-type.cpp new file mode 100644 index 0000000000..695ed1d83f --- /dev/null +++ b/tools/clang-tidy/test/readability-const-return-type.cpp @@ -0,0 +1,5 @@ +const int p1() { +// CHECK-MESSAGES: [[@LINE-1]]:1: warning: return type 'const int' is 'const'-qualified at the top level, which may reduce code readability without improving const correctness +// CHECK-FIXES: int p1() { + return 1; +} diff --git a/tools/clang-tidy/test/readability-const-return-type.json b/tools/clang-tidy/test/readability-const-return-type.json new file mode 100644 index 0000000000..6fade84506 --- /dev/null +++ b/tools/clang-tidy/test/readability-const-return-type.json @@ -0,0 +1 @@ +[["warning", "return type 'const int' is 'const'-qualified at the top level, which may reduce code readability without improving const correctness", "readability-const-return-type"], {"reliability": "high"}]
\ No newline at end of file diff --git a/tools/clang-tidy/test/readability-container-size-empty.cpp b/tools/clang-tidy/test/readability-container-size-empty.cpp new file mode 100644 index 0000000000..1dcfe68bd7 --- /dev/null +++ b/tools/clang-tidy/test/readability-container-size-empty.cpp @@ -0,0 +1,7 @@ +#include "structures.h" + +void foo() { + std::string a; + if (a.size()) + return; +} diff --git a/tools/clang-tidy/test/readability-container-size-empty.json b/tools/clang-tidy/test/readability-container-size-empty.json new file mode 100644 index 0000000000..4d8ffb5ae4 --- /dev/null +++ b/tools/clang-tidy/test/readability-container-size-empty.json @@ -0,0 +1 @@ +[["warning", "the 'empty' method should be used to check for emptiness instead of 'size'", "readability-container-size-empty"], {"reliability": "high"}]
\ No newline at end of file diff --git a/tools/clang-tidy/test/readability-delete-null-pointer.cpp b/tools/clang-tidy/test/readability-delete-null-pointer.cpp new file mode 100644 index 0000000000..e083404043 --- /dev/null +++ b/tools/clang-tidy/test/readability-delete-null-pointer.cpp @@ -0,0 +1,6 @@ +void func() { + int* f = 0; + if (f) { + delete f; + } +} diff --git a/tools/clang-tidy/test/readability-delete-null-pointer.json b/tools/clang-tidy/test/readability-delete-null-pointer.json new file mode 100644 index 0000000000..2fd06e657d --- /dev/null +++ b/tools/clang-tidy/test/readability-delete-null-pointer.json @@ -0,0 +1 @@ +[["warning", "'if' statement is unnecessary; deleting null pointer has no effect", "readability-delete-null-pointer"], {"reliability": "high"}]
\ No newline at end of file diff --git a/tools/clang-tidy/test/readability-else-after-return.cpp b/tools/clang-tidy/test/readability-else-after-return.cpp new file mode 100644 index 0000000000..2c72b68a92 --- /dev/null +++ b/tools/clang-tidy/test/readability-else-after-return.cpp @@ -0,0 +1,10 @@ +void f() { + +} + +void foo() { + if (true) + return; + else + f(); +} diff --git a/tools/clang-tidy/test/readability-else-after-return.json b/tools/clang-tidy/test/readability-else-after-return.json new file mode 100644 index 0000000000..101b9c3bd9 --- /dev/null +++ b/tools/clang-tidy/test/readability-else-after-return.json @@ -0,0 +1 @@ +[["warning", "do not use 'else' after 'return'", "readability-else-after-return"], {"reliability": "high"}]
\ No newline at end of file diff --git a/tools/clang-tidy/test/readability-implicit-bool-conversion.cpp b/tools/clang-tidy/test/readability-implicit-bool-conversion.cpp new file mode 100644 index 0000000000..c30089a126 --- /dev/null +++ b/tools/clang-tidy/test/readability-implicit-bool-conversion.cpp @@ -0,0 +1,55 @@ + +#define MOZ_IMPLICIT __attribute__((annotate("moz_implicit"))) + +void takesChar(char); +void takesShort(short); +void takesInt(int); +void takesLong(long); + +void takesUChar(unsigned char); +void takesUShort(unsigned short); +void takesUInt(unsigned int); +void takesULong(unsigned long); + +struct InitializedWithInt { + MOZ_IMPLICIT InitializedWithInt(int); +}; + +void f() { + bool b = true; + char s0 = b; + short s1 = b; + int s2 = b; + long s3 = b; + + unsigned char u0 = b; + unsigned short u1 = b; + unsigned u2 = b; + unsigned long u3 = b; + + takesChar(b); + takesShort(b); + takesInt(b); + takesLong(b); + takesUChar(b); + takesUShort(b); + takesUInt(b); + takesULong(b); + + InitializedWithInt i = b; + (InitializedWithInt(b)); + + bool x = b; + + int exp = (int)true; + + if (x == b) {} + if (x != b) {} + + if (b == exp) {} + if (exp == b) {} + + char* ptr; + // Shouldn't trigger a checker warning since we are using AllowPointerConditions + if (ptr) {} +} diff --git a/tools/clang-tidy/test/readability-implicit-bool-conversion.json b/tools/clang-tidy/test/readability-implicit-bool-conversion.json new file mode 100644 index 0000000000..548e8eec34 --- /dev/null +++ b/tools/clang-tidy/test/readability-implicit-bool-conversion.json @@ -0,0 +1 @@ +[["warning", "implicit conversion bool -> 'char'", "readability-implicit-bool-conversion"], ["warning", "implicit conversion bool -> 'short'", "readability-implicit-bool-conversion"], ["warning", "implicit conversion bool -> 'int'", "readability-implicit-bool-conversion"], ["warning", "implicit conversion bool -> 'long'", "readability-implicit-bool-conversion"], ["warning", "implicit conversion bool -> 'unsigned char'", "readability-implicit-bool-conversion"], ["warning", "implicit conversion bool -> 'unsigned short'", "readability-implicit-bool-conversion"], ["warning", "implicit conversion bool -> 'unsigned int'", "readability-implicit-bool-conversion"], ["warning", "implicit conversion bool -> 'unsigned long'", "readability-implicit-bool-conversion"], ["warning", "implicit conversion bool -> 'char'", "readability-implicit-bool-conversion"], ["warning", "implicit conversion bool -> 'short'", "readability-implicit-bool-conversion"], ["warning", "implicit conversion bool -> 'int'", "readability-implicit-bool-conversion"], ["warning", "implicit conversion bool -> 'long'", "readability-implicit-bool-conversion"], ["warning", "implicit conversion bool -> 'unsigned char'", "readability-implicit-bool-conversion"], ["warning", "implicit conversion bool -> 'unsigned short'", "readability-implicit-bool-conversion"], ["warning", "implicit conversion bool -> 'unsigned int'", "readability-implicit-bool-conversion"], ["warning", "implicit conversion bool -> 'unsigned long'", "readability-implicit-bool-conversion"], ["warning", "implicit conversion bool -> 'int'", "readability-implicit-bool-conversion"], ["warning", "implicit conversion bool -> 'int'", "readability-implicit-bool-conversion"], ["warning", "implicit conversion bool -> 'int'", "readability-implicit-bool-conversion"], ["warning", "implicit conversion bool -> 'int'", "readability-implicit-bool-conversion"]]
\ No newline at end of file diff --git a/tools/clang-tidy/test/readability-inconsistent-declaration-parameter-name.cpp b/tools/clang-tidy/test/readability-inconsistent-declaration-parameter-name.cpp new file mode 100644 index 0000000000..acf13b240b --- /dev/null +++ b/tools/clang-tidy/test/readability-inconsistent-declaration-parameter-name.cpp @@ -0,0 +1,6 @@ +struct S { + void f(int x); +}; + +void S::f(int y) { +} diff --git a/tools/clang-tidy/test/readability-inconsistent-declaration-parameter-name.json b/tools/clang-tidy/test/readability-inconsistent-declaration-parameter-name.json new file mode 100644 index 0000000000..b26b918fd1 --- /dev/null +++ b/tools/clang-tidy/test/readability-inconsistent-declaration-parameter-name.json @@ -0,0 +1 @@ +[["warning", "function 'S::f' has a definition with different parameter names", "readability-inconsistent-declaration-parameter-name"], {"reliability": "high"}]
\ No newline at end of file diff --git a/tools/clang-tidy/test/readability-isolate-declaration.cpp b/tools/clang-tidy/test/readability-isolate-declaration.cpp new file mode 100644 index 0000000000..5d64e0171f --- /dev/null +++ b/tools/clang-tidy/test/readability-isolate-declaration.cpp @@ -0,0 +1,7 @@ +void f() { + int * pointer = nullptr, value = 42, * const const_ptr = &value; + // This declaration will be diagnosed and transformed into: + // int * pointer = nullptr; + // int value = 42; + // int * const const_ptr = &value; +} diff --git a/tools/clang-tidy/test/readability-isolate-declaration.json b/tools/clang-tidy/test/readability-isolate-declaration.json new file mode 100644 index 0000000000..ced684f581 --- /dev/null +++ b/tools/clang-tidy/test/readability-isolate-declaration.json @@ -0,0 +1 @@ +[["warning", "multiple declarations in a single statement reduces readability", "readability-isolate-declaration"], {"reliability": "high"}]
\ No newline at end of file diff --git a/tools/clang-tidy/test/readability-magic-numbers.cpp b/tools/clang-tidy/test/readability-magic-numbers.cpp new file mode 100644 index 0000000000..430fa17056 --- /dev/null +++ b/tools/clang-tidy/test/readability-magic-numbers.cpp @@ -0,0 +1,4 @@ +void func() { + int radius = 2; + double circleArea = 3.1415926535 * radius * radius; +} diff --git a/tools/clang-tidy/test/readability-magic-numbers.json b/tools/clang-tidy/test/readability-magic-numbers.json new file mode 100644 index 0000000000..206c0d7d5b --- /dev/null +++ b/tools/clang-tidy/test/readability-magic-numbers.json @@ -0,0 +1 @@ +[["warning", "3.1415926535 is a magic number; consider replacing it with a named constant", "readability-magic-numbers"], {"reliability": "high"}]
\ No newline at end of file diff --git a/tools/clang-tidy/test/readability-misleading-indentation.cpp b/tools/clang-tidy/test/readability-misleading-indentation.cpp new file mode 100644 index 0000000000..8b23010170 --- /dev/null +++ b/tools/clang-tidy/test/readability-misleading-indentation.cpp @@ -0,0 +1,20 @@ +void f() +{ +} + +void foo() { + if (1) + if (0) + f(); + else + f(); +} + +void foo2() { + constexpr bool a = true; + if constexpr (a) { + f(); + } else { + f(); + } +} diff --git a/tools/clang-tidy/test/readability-misleading-indentation.json b/tools/clang-tidy/test/readability-misleading-indentation.json new file mode 100644 index 0000000000..d19dc94b13 --- /dev/null +++ b/tools/clang-tidy/test/readability-misleading-indentation.json @@ -0,0 +1 @@ +[["warning", "different indentation for 'if' and corresponding 'else'", "readability-misleading-indentation"], {"reliability": "high"}]
\ No newline at end of file diff --git a/tools/clang-tidy/test/readability-non-const-parameter.cpp b/tools/clang-tidy/test/readability-non-const-parameter.cpp new file mode 100644 index 0000000000..5a0ffd0e30 --- /dev/null +++ b/tools/clang-tidy/test/readability-non-const-parameter.cpp @@ -0,0 +1,5 @@ +void warn1(int *first, int *last) { + *first = 0; + if (first < last) { + } +} diff --git a/tools/clang-tidy/test/readability-non-const-parameter.json b/tools/clang-tidy/test/readability-non-const-parameter.json new file mode 100644 index 0000000000..d474cccb96 --- /dev/null +++ b/tools/clang-tidy/test/readability-non-const-parameter.json @@ -0,0 +1 @@ +[["warning", "pointer parameter 'last' can be pointer to const", "readability-non-const-parameter"], {"reliability": "high"}]
\ No newline at end of file diff --git a/tools/clang-tidy/test/readability-qualified-auto.cpp b/tools/clang-tidy/test/readability-qualified-auto.cpp new file mode 100644 index 0000000000..03c5164e2c --- /dev/null +++ b/tools/clang-tidy/test/readability-qualified-auto.cpp @@ -0,0 +1,6 @@ +typedef int *MyPtr; +MyPtr getPtr(); + +void foo() { + auto TdNakedPtr = getPtr(); +} diff --git a/tools/clang-tidy/test/readability-qualified-auto.json b/tools/clang-tidy/test/readability-qualified-auto.json new file mode 100644 index 0000000000..602ae52b7e --- /dev/null +++ b/tools/clang-tidy/test/readability-qualified-auto.json @@ -0,0 +1 @@ +[["warning", "'auto TdNakedPtr' can be declared as 'auto *TdNakedPtr'", "readability-qualified-auto"], {"reliability": "high"}]
\ No newline at end of file diff --git a/tools/clang-tidy/test/readability-redundant-control-flow.cpp b/tools/clang-tidy/test/readability-redundant-control-flow.cpp new file mode 100644 index 0000000000..d221715542 --- /dev/null +++ b/tools/clang-tidy/test/readability-redundant-control-flow.cpp @@ -0,0 +1,5 @@ +extern void g(); +void f() { + g(); + return; +} diff --git a/tools/clang-tidy/test/readability-redundant-control-flow.json b/tools/clang-tidy/test/readability-redundant-control-flow.json new file mode 100644 index 0000000000..2a56ffad17 --- /dev/null +++ b/tools/clang-tidy/test/readability-redundant-control-flow.json @@ -0,0 +1 @@ +[["warning", "redundant return statement at the end of a function with a void return type", "readability-redundant-control-flow"], {"reliability": "high"}]
\ No newline at end of file diff --git a/tools/clang-tidy/test/readability-redundant-preprocessor.cpp b/tools/clang-tidy/test/readability-redundant-preprocessor.cpp new file mode 100644 index 0000000000..317905dab8 --- /dev/null +++ b/tools/clang-tidy/test/readability-redundant-preprocessor.cpp @@ -0,0 +1,5 @@ +#ifndef FOO +#ifdef FOO // inner ifdef is considered redundant +void f(); +#endif +#endif diff --git a/tools/clang-tidy/test/readability-redundant-preprocessor.json b/tools/clang-tidy/test/readability-redundant-preprocessor.json new file mode 100644 index 0000000000..0e009dd920 --- /dev/null +++ b/tools/clang-tidy/test/readability-redundant-preprocessor.json @@ -0,0 +1 @@ +[["warning", "nested redundant #ifdef; consider removing it", "readability-redundant-preprocessor"], {"reliability": "high"}]
\ No newline at end of file diff --git a/tools/clang-tidy/test/readability-redundant-smartptr-get.cpp b/tools/clang-tidy/test/readability-redundant-smartptr-get.cpp new file mode 100644 index 0000000000..66eb8d6c37 --- /dev/null +++ b/tools/clang-tidy/test/readability-redundant-smartptr-get.cpp @@ -0,0 +1,19 @@ +#define NULL __null + +namespace std { + +template <typename T> +struct unique_ptr { + T& operator*() const; + T* operator->() const; + T* get() const; + explicit operator bool() const noexcept; +}; +} + +struct A { +}; + +void foo() { + A& b2 = *std::unique_ptr<A>().get(); +} diff --git a/tools/clang-tidy/test/readability-redundant-smartptr-get.json b/tools/clang-tidy/test/readability-redundant-smartptr-get.json new file mode 100644 index 0000000000..587ee6c890 --- /dev/null +++ b/tools/clang-tidy/test/readability-redundant-smartptr-get.json @@ -0,0 +1 @@ +[["warning", "redundant get() call on smart pointer", "readability-redundant-smartptr-get"], {"reliability": "high"}]
\ No newline at end of file diff --git a/tools/clang-tidy/test/readability-redundant-string-cstr.cpp b/tools/clang-tidy/test/readability-redundant-string-cstr.cpp new file mode 100644 index 0000000000..d35a2998e5 --- /dev/null +++ b/tools/clang-tidy/test/readability-redundant-string-cstr.cpp @@ -0,0 +1,7 @@ +#include "structures.h" + +void foo() { + std::string a = "Mozilla"; + std::string tmp; + tmp.assign(a.c_str()); +} diff --git a/tools/clang-tidy/test/readability-redundant-string-cstr.json b/tools/clang-tidy/test/readability-redundant-string-cstr.json new file mode 100644 index 0000000000..c0faf789a3 --- /dev/null +++ b/tools/clang-tidy/test/readability-redundant-string-cstr.json @@ -0,0 +1 @@ +[["warning", "redundant call to 'c_str'", "readability-redundant-string-cstr"], {"reliability": "high"}]
\ No newline at end of file diff --git a/tools/clang-tidy/test/readability-redundant-string-init.cpp b/tools/clang-tidy/test/readability-redundant-string-init.cpp new file mode 100644 index 0000000000..39bae4bd56 --- /dev/null +++ b/tools/clang-tidy/test/readability-redundant-string-init.cpp @@ -0,0 +1,5 @@ +#include "structures.h" + +int foo() { + std::string a = ""; +} diff --git a/tools/clang-tidy/test/readability-redundant-string-init.json b/tools/clang-tidy/test/readability-redundant-string-init.json new file mode 100644 index 0000000000..689f98957e --- /dev/null +++ b/tools/clang-tidy/test/readability-redundant-string-init.json @@ -0,0 +1 @@ +[["warning", "redundant string initialization", "readability-redundant-string-init"], {"reliability": "high"}]
\ No newline at end of file diff --git a/tools/clang-tidy/test/readability-simplify-boolean-expr.cpp b/tools/clang-tidy/test/readability-simplify-boolean-expr.cpp new file mode 100644 index 0000000000..277a469880 --- /dev/null +++ b/tools/clang-tidy/test/readability-simplify-boolean-expr.cpp @@ -0,0 +1,2 @@ +bool a1 = false; +bool aa = false == a1; diff --git a/tools/clang-tidy/test/readability-simplify-boolean-expr.json b/tools/clang-tidy/test/readability-simplify-boolean-expr.json new file mode 100644 index 0000000000..8cdba5f2af --- /dev/null +++ b/tools/clang-tidy/test/readability-simplify-boolean-expr.json @@ -0,0 +1 @@ +[["warning", "redundant boolean literal supplied to boolean operator", "readability-simplify-boolean-expr"], {"reliability": "high"}]
\ No newline at end of file diff --git a/tools/clang-tidy/test/readability-static-accessed-through-instance.cpp b/tools/clang-tidy/test/readability-static-accessed-through-instance.cpp new file mode 100644 index 0000000000..95f13b994c --- /dev/null +++ b/tools/clang-tidy/test/readability-static-accessed-through-instance.cpp @@ -0,0 +1,11 @@ +struct C { + static int x; +}; + +int C::x = 0; + +// Expressions with side effects +C &f(int, int, int, int); +void g() { + f(1, 2, 3, 4).x; +} diff --git a/tools/clang-tidy/test/readability-static-accessed-through-instance.json b/tools/clang-tidy/test/readability-static-accessed-through-instance.json new file mode 100644 index 0000000000..cfc55ec1b0 --- /dev/null +++ b/tools/clang-tidy/test/readability-static-accessed-through-instance.json @@ -0,0 +1 @@ +[["warning", "static member accessed through instance", "readability-static-accessed-through-instance"], {"reliability": "high"}]
\ No newline at end of file diff --git a/tools/clang-tidy/test/readability-uniqueptr-delete-release.cpp b/tools/clang-tidy/test/readability-uniqueptr-delete-release.cpp new file mode 100644 index 0000000000..4fce9cde4e --- /dev/null +++ b/tools/clang-tidy/test/readability-uniqueptr-delete-release.cpp @@ -0,0 +1,6 @@ +#include "structures.h" + +int foo() { + std::unique_ptr<int> P; + delete P.release(); +} diff --git a/tools/clang-tidy/test/readability-uniqueptr-delete-release.json b/tools/clang-tidy/test/readability-uniqueptr-delete-release.json new file mode 100644 index 0000000000..9621fe9948 --- /dev/null +++ b/tools/clang-tidy/test/readability-uniqueptr-delete-release.json @@ -0,0 +1 @@ +[["warning", "prefer '= nullptr' to 'delete x.release()' to reset unique_ptr<> objects", "readability-uniqueptr-delete-release"], {"reliability": "high"}]
\ No newline at end of file diff --git a/tools/clang-tidy/test/structures.h b/tools/clang-tidy/test/structures.h new file mode 100644 index 0000000000..0966109635 --- /dev/null +++ b/tools/clang-tidy/test/structures.h @@ -0,0 +1,108 @@ +// Proxy file in order to define generic data types, to avoid binding with system headers + +typedef __SIZE_TYPE__ size_t; + +namespace std { + +typedef size_t size_t; + +template <class T> +class vector { + public: + typedef T* iterator; + typedef const T* const_iterator; + typedef T& reference; + typedef const T& const_reference; + typedef size_t size_type; + + explicit vector(); + explicit vector(size_type n); + + void swap(vector &other); + void push_back(const T& val); + + template <class... Args> void emplace_back(Args &&... args); + + void reserve(size_t n); + void resize(size_t n); + + size_t size(); + const_reference operator[] (size_type) const; + reference operator[] (size_type); + + const_iterator begin() const; + const_iterator end() const; +}; + +template <typename T> +class basic_string { +public: + typedef basic_string<T> _Type; + basic_string() {} + basic_string(const T *p); + basic_string(const T *p, size_t count); + basic_string(size_t count, char ch); + ~basic_string() {} + size_t size() const; + bool empty() const; + size_t find (const char* s, size_t pos = 0) const; + const T *c_str() const; + _Type& assign(const T *s); + basic_string<T> &operator=(T ch); + basic_string<T> *operator+=(const basic_string<T> &) {} + friend basic_string<T> operator+(const basic_string<T> &, const basic_string<T> &) {} +}; +typedef basic_string<char> string; +typedef basic_string<wchar_t> wstring; + +string to_string(int value); + +template <typename T> +struct default_delete {}; + +template <typename T, typename D = default_delete<T>> +class unique_ptr { + public: + unique_ptr(); + ~unique_ptr(); + explicit unique_ptr(T*); + template <typename U, typename E> + unique_ptr(unique_ptr<U, E>&&); + T* release(); +}; + +template <class Fp, class... Arguments> +class bind_rt {}; + +template <class Fp, class... Arguments> +bind_rt<Fp, Arguments...> bind(Fp &&, Arguments &&...); +} + +typedef unsigned int uid_t; +typedef unsigned int pid_t; + +int bcmp(void *, void *, size_t); +void bcopy(void *, void *, size_t); +void bzero(void *, size_t); + +int getpw(uid_t uid, char *buf); +int setuid(uid_t uid); + +int mkstemp(char *tmpl); +char *mktemp(char *tmpl); + +pid_t vfork(void); + +int abort() { return 0; } + +#define assert(x) \ + if (!(x)) \ + (void)abort() + +size_t strlen(const char *s); +char *strncat(char *s1, const char *s2, size_t); + +void free(void *ptr); +void *malloc(size_t size); + +void *memset(void *b, int c, size_t len); |