diff options
Diffstat (limited to 'clang-tools-extra/test/clang-tidy/checkers/cert')
11 files changed, 0 insertions, 1023 deletions
diff --git a/clang-tools-extra/test/clang-tidy/checkers/cert/dcl58-cpp.cpp b/clang-tools-extra/test/clang-tidy/checkers/cert/dcl58-cpp.cpp deleted file mode 100644 index 01964e7..0000000 --- a/clang-tools-extra/test/clang-tidy/checkers/cert/dcl58-cpp.cpp +++ /dev/null @@ -1,283 +0,0 @@ -// RUN: %check_clang_tidy -std=c++17-or-later %s cert-dcl58-cpp %t -- -- -I %clang_tidy_headers - -#include "system-header-simulation.h" - -namespace A { - namespace B { - int b; - } -} - -namespace A { - namespace B { - int c; - } -} - -namespace posix { -// CHECK-MESSAGES: :[[@LINE+2]]:11: warning: modification of 'posix' namespace can result in undefined behavior [cert-dcl58-cpp] -// CHECK-MESSAGES: :[[@LINE-2]]:11: note: 'posix' namespace opened here -namespace foo { -int foobar; -} -} - -namespace std { -// CHECK-MESSAGES: :[[@LINE+2]]:5: warning: modification of 'std' namespace -// CHECK-MESSAGES: :[[@LINE-2]]:11: note: 'std' namespace opened here -int stdInt; -// CHECK-MESSAGES: :[[@LINE+2]]:5: warning: modification of 'std' namespace -// CHECK-MESSAGES: :[[@LINE-5]]:11: note: 'std' namespace opened here -int stdInt1; -} - -namespace foobar { - namespace std { - int bar; - } -} - -namespace posix { -// CHECK-MESSAGES: :[[@LINE+2]]:11: warning: modification of 'posix' namespace -// CHECK-MESSAGES: :[[@LINE-2]]:11: note: 'posix' namespace opened here -namespace std { -} -} // namespace posix - -namespace posix::a { -// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: modification of 'posix' namespace -// CHECK-MESSAGES: :[[@LINE-2]]:11: note: 'posix' namespace opened here -} - -namespace std { -// no-warning: empty -} // namespace std - -namespace std { -// Warn for non-NamedDecls as well. -// CHECK-MESSAGES: :[[@LINE+2]]:1: warning: modification of 'std' namespace -// CHECK-MESSAGES: :[[@LINE-3]]:11: note: 'std' namespace opened here -static_assert(1 == 1, "non-NamedDecl"); -} // namespace std - -enum class MyError { - ErrorA, - ErrorB -}; - -namespace std { -// no-warning: Class template specialized by a program-defined type. -template <> -struct is_error_code_enum<MyError> : std::true_type {}; - -// no-warning: Function template specialized by a program-defined type. -template<> -void swap<MyError>(MyError &a, MyError &b); -} - -using ConstBoolPtr = const bool *; - -namespace std { -// class template, builtin type -// CHECK-MESSAGES: :[[@LINE+3]]:8: warning: modification of 'std' namespace -// CHECK-MESSAGES: :[[@LINE-3]]:11: note: 'std' namespace opened here -template <> -struct is_error_code_enum<bool> : std::true_type {}; -// function template, builtin type -// CHECK-MESSAGES: :[[@LINE+3]]:6: warning: modification of 'std' namespace -// CHECK-MESSAGES: :[[@LINE-8]]:11: note: 'std' namespace opened here -template <> -void swap<bool>(bool &, bool &); -// CHECK-MESSAGES: :[[@LINE+3]]:6: warning: modification of 'std' namespace -// CHECK-MESSAGES: :[[@LINE-12]]:11: note: 'std' namespace opened here -template <> -void swap<ConstBoolPtr>(ConstBoolPtr &, ConstBoolPtr &); -} // namespace std - -namespace std { -// class template, std type -// CHECK-MESSAGES: :[[@LINE+3]]:8: warning: modification of 'std' namespace -// CHECK-MESSAGES: :[[@LINE-3]]:11: note: 'std' namespace opened here -template <> -struct is_error_code_enum<std::io_errc> : std::true_type {}; -// function template, std type -// CHECK-MESSAGES: :[[@LINE+3]]:6: warning: modification of 'std' namespace -// CHECK-MESSAGES: :[[@LINE-8]]:11: note: 'std' namespace opened here -template <> -void swap<std::io_errc>(std::io_errc &, std::io_errc &); -} // namespace std - -// parameter pack, has program-defined type -namespace std { -// no-warning: there is one program-defined type. -template <> -class tuple<int, MyError, std::io_errc> {}; -} // namespace std - -// parameter pack, only builtin or std type -namespace std { -// Forbid variadic specializations over only `std::` or builtin types. -// CHECK-MESSAGES: :[[@LINE+3]]:7: warning: modification of 'std' namespace -// CHECK-MESSAGES: :[[@LINE-3]]:11: note: 'std' namespace opened here -template <> -class tuple<int, const std::io_errc, float> {}; -} // namespace std - -namespace std { -// Test nested standard declarations. -// CHECK-MESSAGES: :[[@LINE+3]]:8: warning: modification of 'std' namespace -// CHECK-MESSAGES: :[[@LINE-3]]:11: note: 'std' namespace opened here -template <> -struct is_error_code_enum<std::Outer::Inner> : std::true_type {}; -} // namespace std - -namespace std { -// Test nested namespace. -// CHECK-MESSAGES: :[[@LINE+3]]:8: warning: modification of 'std' namespace -// CHECK-MESSAGES: :[[@LINE-3]]:11: note: 'std' namespace opened here -template <> -struct is_error_code_enum<std::detail::X> : std::true_type {}; -} // namespace std - -// Test member function template specializations. -namespace std { -// CHECK-MESSAGES: :[[@LINE+3]]:18: warning: modification of 'std' namespace -// CHECK_MESSAGES: :[[@LINE-2]]:11: note: 'std' namespace opened here -template <> -bool less<void>::operator()<int &&, float &&>(int &&, float &&) const { - return true; -} -// CHECK-MESSAGES: :[[@LINE+3]]:18: warning: modification of 'std' namespace -// CHECK_MESSAGES: :[[@LINE-8]]:11: note: 'std' namespace opened here -template <> -bool less<void>::operator()<MyError &&, MyError &&>(MyError &&, MyError &&) const { - return true; -} -} // namespace std - -// Test member class template specializations. -namespace std { -// CHECK-MESSAGES: :[[@LINE+3]]:20: warning: modification of 'std' namespace -// CHECK_MESSAGES: :[[@LINE-2]]:11: note: 'std' namespace opened here -template <> -struct less<void>::X<bool> {}; -// CHECK-MESSAGES: :[[@LINE+3]]:20: warning: modification of 'std' namespace -// CHECK_MESSAGES: :[[@LINE-6]]:11: note: 'std' namespace opened here -template <> -struct less<void>::X<MyError> {}; -// CHECK-MESSAGES: :[[@LINE+3]]:20: warning: modification of 'std' namespace -// CHECK_MESSAGES: :[[@LINE-10]]:11: note: 'std' namespace opened here -template <typename T> -struct less<void>::X<MyError, T> {}; -} // namespace std - -// We did not open the 'std' namespace, but still specialized the member -// function of 'std::less'. -// CHECK-MESSAGES: :[[@LINE+3]]:23: warning: modification of 'std' namespace -// no-note: There is no opening of 'std' namespace, hence no note emitted. -template <> -bool std::less<void>::operator()<int &&, int &&>(int &&, int &&) const { - return true; -} - -namespace SpaceA { -namespace SpaceB { -class MapKey { - int Type = 0; - -public: - MapKey() = default; - int getType() const { return Type; } -}; -} // namespace SpaceB -} // namespace SpaceA - -// no-warning: Specializing for 'std::hash' for a program-defined type. -template <> -struct std::hash<::SpaceA::SpaceB::MapKey> { - // no-warning - unsigned long operator()(const ::SpaceA::SpaceB::MapKey &K) const { - return K.getType(); - } - // no-warning - bool operator()(const ::SpaceA::SpaceB::MapKey &K1, - const ::SpaceA::SpaceB::MapKey &K2) const { - return K1.getType() < K2.getType(); - } -}; - -using myint = int; - -// The type alias declaration is the same as typedef, does not introduce a -// program-defined type. -// CHECK-MESSAGES: :[[@LINE+2]]:13: warning: modification of 'std' namespace -template <> -struct std::hash<myint> { - // no-warning: The warning was already reported for the struct itself. - unsigned long operator()(const myint &K) const { - return K; - } - // no-warning: The warning was already reported for the struct itself. - bool operator()(const myint &K1, - const myint &K2) const { - return K1 < K2; - } -}; - -// CHECK-MESSAGES: :[[@LINE+2]]:15: warning: modification of 'std' namespace -template <> -struct ::std::hash<long> { - unsigned long operator()(const long &K) const { - return K; - } -}; - -namespace ranges { -namespace detail { -struct diffmax_t {}; -using LongT = long; -} // namespace detail -} // namespace ranges - -namespace std { -// no-warning: specialization with an user-defined type -template <> -struct numeric_limits<::ranges::detail::diffmax_t> { - static constexpr bool is_signed = true; - static constexpr bool is_integer = true; - static constexpr ::ranges::detail::diffmax_t max() noexcept { - return {}; - } -}; -inline constexpr bool numeric_limits<::ranges::detail::diffmax_t>::is_signed; -inline constexpr bool numeric_limits<::ranges::detail::diffmax_t>::is_integer; -} // namespace std - -namespace std { -// specialization with type alias to non-program-defined-type -// CHECK-MESSAGES: :[[@LINE+3]]:8: warning: modification of 'std' namespace -// CHECK_MESSAGES: :[[@LINE-3]]:11: note: 'std' namespace opened here -template <> -struct numeric_limits<::ranges::detail::LongT> { - static constexpr bool is_signed = true; - static constexpr bool is_integer = true; - static constexpr ::ranges::detail::LongT max() noexcept { - return 1; - } -}; -inline constexpr bool numeric_limits<::ranges::detail::LongT>::is_signed; -inline constexpr bool numeric_limits<::ranges::detail::LongT>::is_integer; -} // namespace std - -namespace no_crash { -struct A -{ - friend struct B; -}; - -struct B; - -template<typename> struct T {}; - -T<B> b; -} diff --git a/clang-tools-extra/test/clang-tidy/checkers/cert/flp30-c.c b/clang-tools-extra/test/clang-tidy/checkers/cert/flp30-c.c deleted file mode 100644 index b998588..0000000 --- a/clang-tools-extra/test/clang-tidy/checkers/cert/flp30-c.c +++ /dev/null @@ -1,28 +0,0 @@ -// RUN: %check_clang_tidy %s cert-flp30-c %t - -float g(void); -int c(float); -float f = 1.0f; - -void match(void) { - - for (float x = 0.1f; x <= 1.0f; x += 0.1f) {} - // CHECK-MESSAGES: :[[@LINE-1]]:35: warning: loop induction expression should not have floating-point type [cert-flp30-c] - - for (; f > 0; --f) {} - // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: loop induction expression should not have floating-point type [cert-flp30-c] - - for (float x = 0.0f; c(x); x = g()) {} - // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: loop induction expression should not have floating-point type [cert-flp30-c] - - for (int i=0; i < 10 && f < 2.0f; f++, i++) {} - // CHECK-MESSAGES: :[[@LINE-1]]:37: warning: loop induction expression should not have floating-point type [cert-flp30-c] - // CHECK-MESSAGES: :5:1: note: floating-point type loop induction variable -} - -void not_match(void) { - for (int i = 0; i < 10; i += 1.0f) {} - for (int i = 0; i < 10; ++i) {} - for (int i = 0; i < 10; ++i, f++) {} - for (int i = 0; f < 10.f; ++i) {} -} diff --git a/clang-tools-extra/test/clang-tidy/checkers/cert/limited-randomness.c b/clang-tools-extra/test/clang-tidy/checkers/cert/limited-randomness.c deleted file mode 100644 index 32e4a07..0000000 --- a/clang-tools-extra/test/clang-tidy/checkers/cert/limited-randomness.c +++ /dev/null @@ -1,13 +0,0 @@ -// RUN: %check_clang_tidy %s cert-msc30-c %t - -extern int rand(void); -int nonrand(void); - -int cTest(void) { - int i = rand(); - // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: rand() has limited randomness [cert-msc30-c] - - int k = nonrand(); - - return 0; -} diff --git a/clang-tools-extra/test/clang-tidy/checkers/cert/limited-randomness.cpp b/clang-tools-extra/test/clang-tidy/checkers/cert/limited-randomness.cpp deleted file mode 100644 index 845b735..0000000 --- a/clang-tools-extra/test/clang-tidy/checkers/cert/limited-randomness.cpp +++ /dev/null @@ -1,28 +0,0 @@ -// RUN: %check_clang_tidy %s cert-msc50-cpp %t - -int rand(); -int rand(int); - -namespace std { -using ::rand; -} - -namespace nonstd { - int rand(); -} - -void testFunction1() { - int i = std::rand(); - // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: rand() has limited randomness; use C++11 random library instead [cert-msc50-cpp] - - int j = ::rand(); - // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: rand() has limited randomness; use C++11 random library instead [cert-msc50-cpp] - - int k = rand(i); - - int l = nonstd::rand(); - - int m = rand(); - // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: rand() has limited randomness; use C++11 random library instead [cert-msc50-cpp] -} - diff --git a/clang-tools-extra/test/clang-tidy/checkers/cert/mem57-cpp-cpp17.cpp b/clang-tools-extra/test/clang-tidy/checkers/cert/mem57-cpp-cpp17.cpp deleted file mode 100644 index 38ffcbd..0000000 --- a/clang-tools-extra/test/clang-tidy/checkers/cert/mem57-cpp-cpp17.cpp +++ /dev/null @@ -1,12 +0,0 @@ -// RUN: %check_clang_tidy %s -std=c++14 cert-mem57-cpp %t -// RUN: clang-tidy -checks='-*,cert-mem57-cpp' --extra-arg=-Wno-unused-variable --warnings-as-errors='*' %s -- -std=c++17 -faligned-allocation -// RUN: clang-tidy -checks='-*,cert-mem57-cpp' --extra-arg=-Wno-unused-variable --warnings-as-errors='*' %s -- -std=c++17 -faligned-allocation - -struct alignas(128) Vector { - char Elems[128]; -}; - -void f() { - auto *V1 = new Vector; // CHECK-MESSAGES: warning: allocation function returns a pointer with alignment {{[0-9]+}} but the over-aligned type being allocated requires alignment 128 [cert-mem57-cpp] - auto *V1_Arr = new Vector[2]; // CHECK-MESSAGES: warning: allocation function returns a pointer with alignment {{[0-9]+}} but the over-aligned type being allocated requires alignment 128 [cert-mem57-cpp] -} diff --git a/clang-tools-extra/test/clang-tidy/checkers/cert/mem57-cpp.cpp b/clang-tools-extra/test/clang-tidy/checkers/cert/mem57-cpp.cpp deleted file mode 100644 index e0300e3..0000000 --- a/clang-tools-extra/test/clang-tidy/checkers/cert/mem57-cpp.cpp +++ /dev/null @@ -1,39 +0,0 @@ -// RUN: %check_clang_tidy %s -std=c++14 cert-mem57-cpp %t - -namespace std { -typedef __typeof(sizeof(int)) size_t; -void *aligned_alloc(size_t, size_t); -void free(void *); -} // namespace std - -struct alignas(128) Vector1 { - char elems[128]; -}; - -struct Vector2 { - char elems[128]; -}; - -struct alignas(128) Vector3 { - char elems[128]; - static void *operator new(std::size_t nbytes) noexcept(true) { - return std::aligned_alloc(alignof(Vector3), nbytes); - } - static void operator delete(void *p) { - std::free(p); - } -}; - -struct alignas(8) Vector4 { - char elems[32]; -}; - -void f() { - auto *V1 = new Vector1; - // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: allocation function returns a pointer with alignment {{[0-9]+}} but the over-aligned type being allocated requires alignment 128 [cert-mem57-cpp] - auto *V2 = new Vector2; - auto *V3 = new Vector3; - auto *V4 = new Vector4; - auto *V1_Arr = new Vector1[2]; - // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: allocation function returns a pointer with alignment {{[0-9]+}} but the over-aligned type being allocated requires alignment 128 [cert-mem57-cpp] -} diff --git a/clang-tools-extra/test/clang-tidy/checkers/cert/msc32-c.c b/clang-tools-extra/test/clang-tidy/checkers/cert/msc32-c.c deleted file mode 100644 index 0a1d79b..0000000 --- a/clang-tools-extra/test/clang-tidy/checkers/cert/msc32-c.c +++ /dev/null @@ -1,27 +0,0 @@ -// RUN: %check_clang_tidy %s cert-msc32-c %t -- -config="{CheckOptions: {cert-msc32-c.DisallowedSeedTypes: 'some_type,time_t'}}" -- -std=c99 - -void srand(int seed); -typedef int time_t; -time_t time(time_t *t); - -void f(void) { - srand(1); - // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: random number generator seeded with a constant value will generate a predictable sequence of values [cert-msc32-c] - - const int a = 1; - srand(a); - // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: random number generator seeded with a constant value will generate a predictable sequence of values [cert-msc32-c] - - time_t t; - srand(time(&t)); // Disallowed seed type - // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: random number generator seeded with a disallowed source of seed value will generate a predictable sequence of values [cert-msc32-c] -} - -void g(void) { - typedef int user_t; - user_t a = 1; - srand(a); - - int b = 1; - srand(b); // Can not evaluate as int -} diff --git a/clang-tools-extra/test/clang-tidy/checkers/cert/msc51-cpp.cpp b/clang-tools-extra/test/clang-tidy/checkers/cert/msc51-cpp.cpp deleted file mode 100644 index 637ba58..0000000 --- a/clang-tools-extra/test/clang-tidy/checkers/cert/msc51-cpp.cpp +++ /dev/null @@ -1,211 +0,0 @@ -// RUN: %check_clang_tidy %s cert-msc51-cpp %t -- \ -// RUN: -config="{CheckOptions: {cert-msc51-cpp.DisallowedSeedTypes: 'some_type,time_t'}}" - -namespace std { - -void srand(int seed); - -template <class UIntType, UIntType a, UIntType c, UIntType m> -struct linear_congruential_engine { - linear_congruential_engine(int _ = 0); - void seed(int _ = 0); -}; -using default_random_engine = linear_congruential_engine<unsigned int, 1, 2, 3>; - -using size_t = int; -template <class UIntType, size_t w, size_t n, size_t m, size_t r, - UIntType a, size_t u, UIntType d, size_t s, - UIntType b, size_t t, - UIntType c, size_t l, UIntType f> -struct mersenne_twister_engine { - mersenne_twister_engine(int _ = 0); - void seed(int _ = 0); -}; -using mt19937 = mersenne_twister_engine<unsigned int, 32, 624, 397, 21, 0x9908b0df, 11, 0xffffffff, 7, 0x9d2c5680, 15, 0xefc60000, 18, 1812433253>; - -template <class UIntType, size_t w, size_t s, size_t r> -struct subtract_with_carry_engine { - subtract_with_carry_engine(int _ = 0); - void seed(int _ = 0); -}; -using ranlux24_base = subtract_with_carry_engine<unsigned int, 24, 10, 24>; - -template <class Engine, size_t p, size_t r> -struct discard_block_engine { - discard_block_engine(); - discard_block_engine(int _); - void seed(); - void seed(int _); -}; -using ranlux24 = discard_block_engine<ranlux24_base, 223, 23>; - -template <class Engine, size_t w, class UIntType> -struct independent_bits_engine { - independent_bits_engine(); - independent_bits_engine(int _); - void seed(); - void seed(int _); -}; -using independent_bits = independent_bits_engine<ranlux24_base, 223, int>; - -template <class Engine, size_t k> -struct shuffle_order_engine { - shuffle_order_engine(); - shuffle_order_engine(int _); - void seed(); - void seed(int _); -}; -using shuffle_order = shuffle_order_engine<ranlux24_base, 223>; - -struct random_device { - random_device(); - int operator()(); -}; -} // namespace std - -using time_t = unsigned int; -time_t time(time_t *t); - -void f() { - const int seed = 2; - time_t t; - - std::srand(0); - // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: random number generator seeded with a constant value will generate a predictable sequence of values [cert-msc51-cpp] - std::srand(seed); - // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: random number generator seeded with a constant value will generate a predictable sequence of values [cert-msc51-cpp] - std::srand(time(&t)); - // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: random number generator seeded with a disallowed source of seed value will generate a predictable sequence of values [cert-msc51-cpp] - - // One instantiation for every engine - std::default_random_engine engine1; - // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: random number generator seeded with a default argument will generate a predictable sequence of values [cert-msc51-cpp] - std::default_random_engine engine2(1); - // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: random number generator seeded with a constant value will generate a predictable sequence of values [cert-msc51-cpp] - std::default_random_engine engine3(seed); - // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: random number generator seeded with a constant value will generate a predictable sequence of values [cert-msc51-cpp] - std::default_random_engine engine4(time(&t)); - // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: random number generator seeded with a disallowed source of seed value will generate a predictable sequence of values [cert-msc51-cpp] - engine1.seed(); - // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: random number generator seeded with a default argument will generate a predictable sequence of values [cert-msc51-cpp] - engine1.seed(1); - // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: random number generator seeded with a constant value will generate a predictable sequence of values [cert-msc51-cpp] - engine1.seed(seed); - // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: random number generator seeded with a constant value will generate a predictable sequence of values [cert-msc51-cpp] - engine1.seed(time(&t)); - // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: random number generator seeded with a disallowed source of seed value will generate a predictable sequence of values [cert-msc51-cpp] - - std::mt19937 engine5; - // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: random number generator seeded with a default argument will generate a predictable sequence of values [cert-msc51-cpp] - std::mt19937 engine6(1); - // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: random number generator seeded with a constant value will generate a predictable sequence of values [cert-msc51-cpp] - std::mt19937 engine7(seed); - // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: random number generator seeded with a constant value will generate a predictable sequence of values [cert-msc51-cpp] - std::mt19937 engine8(time(&t)); - // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: random number generator seeded with a disallowed source of seed value will generate a predictable sequence of values [cert-msc51-cpp] - engine5.seed(); - // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: random number generator seeded with a default argument will generate a predictable sequence of values [cert-msc51-cpp] - engine5.seed(1); - // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: random number generator seeded with a constant value will generate a predictable sequence of values [cert-msc51-cpp] - engine5.seed(seed); - // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: random number generator seeded with a constant value will generate a predictable sequence of values [cert-msc51-cpp] - engine5.seed(time(&t)); - // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: random number generator seeded with a disallowed source of seed value will generate a predictable sequence of values [cert-msc51-cpp] - - std::ranlux24_base engine9; - // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: random number generator seeded with a default argument will generate a predictable sequence of values [cert-msc51-cpp] - std::ranlux24_base engine10(1); - // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: random number generator seeded with a constant value will generate a predictable sequence of values [cert-msc51-cpp] - std::ranlux24_base engine11(seed); - // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: random number generator seeded with a constant value will generate a predictable sequence of values [cert-msc51-cpp] - std::ranlux24_base engine12(time(&t)); - // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: random number generator seeded with a disallowed source of seed value will generate a predictable sequence of values [cert-msc51-cpp] - engine9.seed(); - // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: random number generator seeded with a default argument will generate a predictable sequence of values [cert-msc51-cpp] - engine9.seed(1); - // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: random number generator seeded with a constant value will generate a predictable sequence of values [cert-msc51-cpp] - engine9.seed(seed); - // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: random number generator seeded with a constant value will generate a predictable sequence of values [cert-msc51-cpp] - engine9.seed(time(&t)); - // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: random number generator seeded with a disallowed source of seed value will generate a predictable sequence of values [cert-msc51-cpp] - - std::ranlux24 engine13; - // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: random number generator seeded with a default argument will generate a predictable sequence of values [cert-msc51-cpp] - std::ranlux24 engine14(1); - // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: random number generator seeded with a constant value will generate a predictable sequence of values [cert-msc51-cpp] - std::ranlux24 engine15(seed); - // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: random number generator seeded with a constant value will generate a predictable sequence of values [cert-msc51-cpp] - std::ranlux24 engine16(time(&t)); - // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: random number generator seeded with a disallowed source of seed value will generate a predictable sequence of values [cert-msc51-cpp] - engine13.seed(); - // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: random number generator seeded with a default argument will generate a predictable sequence of values [cert-msc51-cpp] - engine13.seed(1); - // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: random number generator seeded with a constant value will generate a predictable sequence of values [cert-msc51-cpp] - engine13.seed(seed); - // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: random number generator seeded with a constant value will generate a predictable sequence of values [cert-msc51-cpp] - engine13.seed(time(&t)); - // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: random number generator seeded with a disallowed source of seed value will generate a predictable sequence of values [cert-msc51-cpp] - - std::independent_bits engine17; - // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: random number generator seeded with a default argument will generate a predictable sequence of values [cert-msc51-cpp] - std::independent_bits engine18(1); - // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: random number generator seeded with a constant value will generate a predictable sequence of values [cert-msc51-cpp] - std::independent_bits engine19(seed); - // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: random number generator seeded with a constant value will generate a predictable sequence of values [cert-msc51-cpp] - std::independent_bits engine20(time(&t)); - // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: random number generator seeded with a disallowed source of seed value will generate a predictable sequence of values [cert-msc51-cpp] - engine17.seed(); - // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: random number generator seeded with a default argument will generate a predictable sequence of values [cert-msc51-cpp] - engine17.seed(1); - // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: random number generator seeded with a constant value will generate a predictable sequence of values [cert-msc51-cpp] - engine17.seed(seed); - // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: random number generator seeded with a constant value will generate a predictable sequence of values [cert-msc51-cpp] - engine17.seed(time(&t)); - // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: random number generator seeded with a disallowed source of seed value will generate a predictable sequence of values [cert-msc51-cpp] - - std::shuffle_order engine21; - // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: random number generator seeded with a default argument will generate a predictable sequence of values [cert-msc51-cpp] - std::shuffle_order engine22(1); - // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: random number generator seeded with a constant value will generate a predictable sequence of values [cert-msc51-cpp] - std::shuffle_order engine23(seed); - // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: random number generator seeded with a constant value will generate a predictable sequence of values [cert-msc51-cpp] - std::shuffle_order engine24(time(&t)); - // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: random number generator seeded with a disallowed source of seed value will generate a predictable sequence of values [cert-msc51-cpp] - engine21.seed(); - // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: random number generator seeded with a default argument will generate a predictable sequence of values [cert-msc51-cpp] - engine21.seed(1); - // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: random number generator seeded with a constant value will generate a predictable sequence of values [cert-msc51-cpp] - engine21.seed(seed); - // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: random number generator seeded with a constant value will generate a predictable sequence of values [cert-msc51-cpp] - engine21.seed(time(&t)); - // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: random number generator seeded with a disallowed source of seed value will generate a predictable sequence of values [cert-msc51-cpp] -} - -struct A { - A(int _ = 0); - void seed(int _ = 0); -}; - -void g() { - int n = 1; - std::default_random_engine engine1(n); - std::mt19937 engine2(n); - std::ranlux24_base engine3(n); - std::ranlux24 engine4(n); - std::independent_bits engine5(n); - std::shuffle_order engine6(n); - - std::random_device dev; - std::default_random_engine engine7(dev()); - std::mt19937 engine8(dev()); - std::ranlux24_base engine9(dev()); - std::ranlux24 engine10(dev()); - std::independent_bits engine11(dev()); - std::shuffle_order engine12(dev()); - - A a1; - A a2(1); - a1.seed(); - a1.seed(1); - a1.seed(n); -} diff --git a/clang-tools-extra/test/clang-tidy/checkers/cert/oop57-cpp.cpp b/clang-tools-extra/test/clang-tidy/checkers/cert/oop57-cpp.cpp deleted file mode 100644 index e34315f..0000000 --- a/clang-tools-extra/test/clang-tidy/checkers/cert/oop57-cpp.cpp +++ /dev/null @@ -1,104 +0,0 @@ -// RUN: %check_clang_tidy %s cert-oop57-cpp %t -- \ -// RUN: -config='{CheckOptions: \ -// RUN: {cert-oop57-cpp.MemSetNames: mymemset, \ -// RUN: cert-oop57-cpp.MemCpyNames: mymemcpy, \ -// RUN: cert-oop57-cpp.MemCmpNames: mymemcmp}}' \ -// RUN: -- - -void mymemset(void *, unsigned char, decltype(sizeof(int))); -void mymemcpy(void *, const void *, decltype(sizeof(int))); -int mymemcmp(const void *, const void *, decltype(sizeof(int))); - -namespace std { -void memset(void *, unsigned char, decltype(sizeof(int))); -void memcpy(void *, const void *, decltype(sizeof(int))); -void memmove(void *, const void *, decltype(sizeof(int))); -void strcpy(void *, const void *, decltype(sizeof(int))); -int memcmp(const void *, const void *, decltype(sizeof(int))); -int strcmp(const void *, const void *, decltype(sizeof(int))); -} // namespace std - -struct Trivial { - int I; - int J; -}; - -struct NonTrivial { - int I; - int J; - - NonTrivial() : I(0), J(0) {} - NonTrivial &operator=(const NonTrivial &Other) { - I = Other.I; - J = Other.J; - return *this; - } - - bool operator==(const Trivial &Other) const { - return I == Other.I && J == Other.J; - } - bool operator!=(const Trivial &Other) const { - return !(*this == Other); - } -}; - -void foo(const Trivial &Other) { - Trivial Data; - std::memset(&Data, 0, sizeof(Data)); - // CHECK-MESSAGES-NOT: :[[@LINE-1]]:3: warning: calling 'memset' on a non-trivially default constructible class is undefined - std::memset(&Data, 0, sizeof(Trivial)); - // CHECK-MESSAGES-NOT: :[[@LINE-1]]:3: warning: calling 'memset' on a non-trivially default constructible class is undefined - std::memcpy(&Data, &Other, sizeof(Data)); - // CHECK-MESSAGES-NOT: :[[@LINE-1]]:3: warning: calling 'memcpy' on a non-trivially copyable class is undefined - std::memmove(&Data, &Other, sizeof(Data)); - // CHECK-MESSAGES-NOT: :[[@LINE-1]]:3: warning: calling 'memmove' on a non-trivially copyable class is undefined - std::strcpy(&Data, &Other, sizeof(Data)); - // CHECK-MESSAGES-NOT: :[[@LINE-1]]:3: warning: calling 'strcpy' on a non-trivially copyable class is undefined - std::memcmp(&Data, &Other, sizeof(Data)); - // CHECK-MESSAGES-NOT: :[[@LINE-1]]:3: warning: consider using comparison operators instead of calling 'memcmp' - std::strcmp(&Data, &Other, sizeof(Data)); - // CHECK-MESSAGES-NOT: :[[@LINE-1]]:3: warning: consider using comparison operators instead of calling 'strcmp' -} - -void bar(const NonTrivial &Other) { - NonTrivial Data; - std::memset(&Data, 0, sizeof(Data)); - // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: calling 'memset' on a non-trivially default constructible class is undefined - // Check it detects sizeof(Type) as well as sizeof(Instantiation) - std::memset(&Data, 0, sizeof(NonTrivial)); - // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: calling 'memset' on a non-trivially default constructible class is undefined - std::memcpy(&Data, &Other, sizeof(Data)); - // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: calling 'memcpy' on a non-trivially copyable class is undefined - std::memmove(&Data, &Other, sizeof(Data)); - // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: calling 'memmove' on a non-trivially copyable class is undefined - std::strcpy(&Data, &Other, sizeof(Data)); - // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: calling 'strcpy' on a non-trivially copyable class is undefined - std::memcmp(&Data, &Other, sizeof(Data)); - // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: consider using comparison operators instead of calling 'memcmp' - std::strcmp(&Data, &Other, sizeof(Data)); - // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: consider using comparison operators instead of calling 'strcmp' -} - -void baz(const NonTrivial &Other) { - NonTrivial Data; - mymemset(&Data, 0, sizeof(Data)); - // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: calling 'mymemset' on a non-trivially default constructible class is undefined - mymemcpy(&Data, &Other, sizeof(Data)); - // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: calling 'mymemcpy' on a non-trivially copyable class is undefined - mymemcmp(&Data, &Other, sizeof(Data)); - // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: consider using comparison operators instead of calling 'mymemcmp' -} - -void nonNullSetValue() { - NonTrivial Data; - // Check non-null-valued second argument. - std::memset(&Data, 1, sizeof(Data)); - // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: calling 'memset' on a non-trivially default constructible class is undefined -} - -void nonLiteralSetValue(char C) { - NonTrivial Data; - // Check non-literal second argument. - std::memset(&Data, C, sizeof(Data)); - // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: calling 'memset' on a non-trivially default constructible class is undefined -} diff --git a/clang-tools-extra/test/clang-tidy/checkers/cert/oop58-cpp.cpp b/clang-tools-extra/test/clang-tidy/checkers/cert/oop58-cpp.cpp deleted file mode 100644 index 223248c..0000000 --- a/clang-tools-extra/test/clang-tidy/checkers/cert/oop58-cpp.cpp +++ /dev/null @@ -1,149 +0,0 @@ -// RUN: %check_clang_tidy %s cert-oop58-cpp %t - -// Example test cases from CERT rule -// https://wiki.sei.cmu.edu/confluence/display/cplusplus/OOP58-CPP.+Copy+operations+must+not+mutate+the+source+object -namespace test_mutating_noncompliant_example { -class A { - mutable int m; - -public: - A() : m(0) {} - explicit A(int m) : m(m) {} - - A(const A &other) : m(other.m) { - other.m = 0; - // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: mutating copied object - } - - A &operator=(const A &other) { - if (&other != this) { - m = other.m; - other.m = 0; - // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: mutating copied object - } - return *this; - } - - int get_m() const { return m; } -}; -} // namespace test_mutating_noncompliant_example - -namespace test_mutating_compliant_example { -class B { - int m; - -public: - B() : m(0) {} - explicit B(int m) : m(m) {} - - B(const B &other) : m(other.m) {} - B(B &&other) : m(other.m) { - other.m = 0; //no-warning: mutation allowed in move constructor - } - - B &operator=(const B &other) { - if (&other != this) { - m = other.m; - } - return *this; - } - - B &operator=(B &&other) { - m = other.m; - other.m = 0; //no-warning: mutation allowed in move assignment operator - return *this; - } - - int get_m() const { return m; } -}; -} // namespace test_mutating_compliant_example - -namespace test_mutating_pointer { -class C { - C *ptr; - int value; - - C(); - C(C &other) { - other = {}; - // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: mutating copied object - other.ptr = nullptr; - // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: mutating copied object - other.value = 0; - // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: mutating copied object - - // no-warning: mutating a pointee is allowed - other.ptr->value = 0; - *other.ptr = {}; - } -}; -} // namespace test_mutating_pointer - -namespace test_mutating_indirect_member { -struct S { - int x; -}; - -class D { - S s; - D(D &other) { - other.s = {}; - // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: mutating copied object - other.s.x = 0; - // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: mutating copied object - } -}; -} // namespace test_mutating_indirect_member - -namespace test_mutating_other_object { -class E { - E(); - E(E &other) { - E tmp; - // no-warning: mutating an object that is not the source is allowed - tmp = {}; - } -}; -} // namespace test_mutating_other_object - -namespace test_mutating_member_function { -class F { - int a; - -public: - void bad_func() { a = 12; } - void fine_func() const; - void fine_func_2(int x) { x = 5; } - void questionable_func(); - - F(F &other) : a(other.a) { - this->bad_func(); // no-warning: mutating this is allowed - - other.bad_func(); - // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: call mutates copied object - - other.fine_func(); - other.fine_func_2(42); - other.questionable_func(); - } -}; -} // namespace test_mutating_member_function - -namespace test_mutating_function_on_nested_object { -struct S { - int x; - void mutate(int y) { - x = y; - } -}; - -class G { - S s; - G(G &other) { - s.mutate(0); // no-warning: mutating this is allowed - - other.s.mutate(0); - // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: call mutates copied object - } -}; -} // namespace test_mutating_function_on_nested_object diff --git a/clang-tools-extra/test/clang-tidy/checkers/cert/throw-exception-type.cpp b/clang-tools-extra/test/clang-tidy/checkers/cert/throw-exception-type.cpp deleted file mode 100644 index 34ca837..0000000 --- a/clang-tools-extra/test/clang-tidy/checkers/cert/throw-exception-type.cpp +++ /dev/null @@ -1,129 +0,0 @@ -// RUN: %check_clang_tidy -std=c++11,c++14 %s cert-err60-cpp %t -- -- -fcxx-exceptions -// FIXME: Split off parts of this test that rely on dynamic exception -// specifications, and run this test in all language modes. -// FIXME: Fix the checker to work in C++17 or later mode. -struct S {}; -struct T : S {}; -struct U { - U() = default; - U(const U&) = default; -}; - -struct V { - V() = default; - V(const V&) noexcept; -}; - -struct W { - W() = default; - W(const W&) noexcept(false); -}; - -struct X { - X() = default; - X(const X&) {} -}; - -struct Y { - Y() = default; - Y(const Y&) throw(); -}; - -struct Z { - Z() = default; - Z(const Z&) throw(int); -}; - -void g() noexcept(false); - -struct A { - A() = default; - A(const A&) noexcept(noexcept(g())); -}; - -struct B { - B() = default; - B(const B&) = default; - B(const A&) noexcept(false); -}; - -class C { - W M; // W is not no-throw copy constructible -public: - C() = default; - C(const C&) = default; -}; - -struct D { - D() = default; - D(const D&) noexcept(false); - D(D&) noexcept(true); -}; - -struct E { - E() = default; - E(E&) noexcept(true); - E(const E&) noexcept(false); -}; - -struct Allocates { - int *x; - Allocates() : x(new int(0)) {} - Allocates(const Allocates &other) : x(new int(*other.x)) {} -}; - -struct OptionallyAllocates { - int *x; - OptionallyAllocates() : x(new int(0)) {} - OptionallyAllocates(const Allocates &other) noexcept(true) { - try { - x = new int(*other.x); - } catch (...) { - x = nullptr; - } - } -}; - -void f() { - throw 12; // ok - throw "test"; // ok - throw S(); // ok - throw T(); // ok - throw U(); // ok - throw V(); // ok - throw W(); // match, noexcept(false) - // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: thrown exception type is not nothrow copy constructible [cert-err60-cpp] - throw X(); // match, no noexcept clause, nontrivial - // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: thrown exception type is not nothrow copy constructible - throw Y(); // ok - throw Z(); // match, throw(int) - // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: thrown exception type is not nothrow copy constructible - throw A(); // match, noexcept(false) - // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: thrown exception type is not nothrow copy constructible - throw B(); // ok - throw C(); // match, C has a member variable that makes it throwing on copy - // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: thrown exception type is not nothrow copy constructible - throw D(); // match, has throwing copy constructor - // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: thrown exception type is not nothrow copy constructible - throw E(); // match, has throwing copy constructor - // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: thrown exception type is not nothrow copy constructible - throw Allocates(); // match, copy constructor throws - // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: thrown exception type is not nothrow copy constructible - throw OptionallyAllocates(); // ok -} - -namespace PR25574 { -struct B { - B(const B&) noexcept; -}; - -struct D : B { - D(); - virtual ~D() noexcept; -}; - -template <typename T> -void f() { - throw D(); -} -} |
