mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-11 10:08:41 +00:00
Bug 1511319 - Ensure that tools/clang-tidy/test doesn't get reformatted using clang-format; r=sylvestre a=Aryx
Reformatting this directory can break some of the tests here. Differential Revision: https://phabricator.services.mozilla.com/D13518
This commit is contained in:
parent
3fb831e8a1
commit
6b07492159
@ -62,6 +62,10 @@ widget/gtk/wayland/gtk-primary-selection-protocol.c
|
|||||||
# and reformatting them can break generating that wrapper.
|
# and reformatting them can break generating that wrapper.
|
||||||
config/windows-h-.*.h
|
config/windows-h-.*.h
|
||||||
|
|
||||||
|
# Exclude tools/clang-tidy/test from automatic reformatting, since it can
|
||||||
|
# break some of the tests in that directory.
|
||||||
|
tools/clang-tidy/test/.*
|
||||||
|
|
||||||
# The XPTCall stubs files have some inline assembly macros
|
# The XPTCall stubs files have some inline assembly macros
|
||||||
# that get reformatted badly. See bug 1510781.
|
# that get reformatted badly. See bug 1510781.
|
||||||
xpcom/reflect/xptcall/md/win32/.*
|
xpcom/reflect/xptcall/md/win32/.*
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
// bugprone-argument-comment
|
// bugprone-argument-comment
|
||||||
|
|
||||||
void f(int x, int y);
|
void f(int x, int y);
|
||||||
void g() { f(/*y=*/0, /*z=*/0); }
|
void g() {
|
||||||
|
f(/*y=*/0, /*z=*/0);
|
||||||
|
}
|
||||||
|
@ -1,16 +1,17 @@
|
|||||||
// https://clang.llvm.org/extra/clang-tidy/checks/bugprone-bool-pointer-implicit-conversion.html
|
// https://clang.llvm.org/extra/clang-tidy/checks/bugprone-bool-pointer-implicit-conversion.html
|
||||||
|
|
||||||
bool test(bool* pointer_to_bool, int* pointer_to_int) {
|
bool test(bool* pointer_to_bool, int* pointer_to_int)
|
||||||
if (pointer_to_bool) { // warning for pointer to bool
|
{
|
||||||
|
if (pointer_to_bool) { // warning for pointer to bool
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pointer_to_int) { // no warning for pointer to int
|
if (pointer_to_int) { // no warning for pointer to int
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!pointer_to_bool) { // no warning, but why not??
|
if (!pointer_to_bool) { // no warning, but why not??
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pointer_to_bool != nullptr) { // no warning for nullptr comparison
|
if (pointer_to_bool != nullptr) { // no warning for nullptr comparison
|
||||||
}
|
}
|
||||||
|
|
||||||
// no warning on return, but why not??
|
// no warning on return, but why not??
|
||||||
|
@ -1,7 +1,3 @@
|
|||||||
namespace na {
|
namespace na { struct A; }
|
||||||
struct A;
|
namespace nb { struct A {}; }
|
||||||
}
|
|
||||||
namespace nb {
|
|
||||||
struct A {};
|
|
||||||
} // namespace nb
|
|
||||||
nb::A a;
|
nb::A a;
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
void f1() {
|
void f1()
|
||||||
|
{
|
||||||
double d;
|
double d;
|
||||||
int x;
|
int x;
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
float f() {
|
float f() {
|
||||||
int a = 2;
|
int a = 2;
|
||||||
int b = 10;
|
int b = 10;
|
||||||
return a / b;
|
return a/b;
|
||||||
}
|
}
|
@ -1,5 +1,5 @@
|
|||||||
#define BAD1 -1
|
#define BAD1 -1
|
||||||
#define BAD2 1 + 2
|
#define BAD2 1+2
|
||||||
#define BAD3(A) (A + 1)
|
#define BAD3(A) (A+1)
|
||||||
#define BAD4(x) ((unsigned char)(x & 0xff))
|
#define BAD4(x) ((unsigned char)(x & 0xff))
|
||||||
#define BAD5(X) A* B = (C*)X + 2
|
#define BAD5(X) A*B=(C*)X+2
|
@ -5,22 +5,24 @@
|
|||||||
|
|
||||||
static int g;
|
static int g;
|
||||||
|
|
||||||
int function_with_side_effects(int i) {
|
int function_with_side_effects(int i)
|
||||||
|
{
|
||||||
g += i;
|
g += i;
|
||||||
return g;
|
return g;
|
||||||
}
|
}
|
||||||
|
|
||||||
void test() {
|
void test()
|
||||||
|
{
|
||||||
int i;
|
int i;
|
||||||
i = MACRO_WITHOUT_REPEATED_ARG(1); // OK
|
i = MACRO_WITHOUT_REPEATED_ARG(1); // OK
|
||||||
i = MACRO_WITH_REPEATED_ARG(1); // OK
|
i = MACRO_WITH_REPEATED_ARG(1); // OK
|
||||||
|
|
||||||
i = MACRO_WITHOUT_REPEATED_ARG(i); // OK
|
i = MACRO_WITHOUT_REPEATED_ARG(i); // OK
|
||||||
i = MACRO_WITH_REPEATED_ARG(i); // OK
|
i = MACRO_WITH_REPEATED_ARG(i); // OK
|
||||||
|
|
||||||
i = MACRO_WITHOUT_REPEATED_ARG(function_with_side_effects(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_WITH_REPEATED_ARG(function_with_side_effects(i)); // NO WARNING
|
||||||
|
|
||||||
i = MACRO_WITHOUT_REPEATED_ARG(i++); // OK
|
i = MACRO_WITHOUT_REPEATED_ARG(i++); // OK
|
||||||
i = MACRO_WITH_REPEATED_ARG(i++); // WARNING
|
i = MACRO_WITH_REPEATED_ARG(i++); // WARNING
|
||||||
}
|
}
|
||||||
|
@ -1 +1,3 @@
|
|||||||
long f(int x) { return (long)(x * 1000); }
|
long f(int x) {
|
||||||
|
return (long)(x * 1000);
|
||||||
|
}
|
@ -5,5 +5,6 @@ void F();
|
|||||||
F()
|
F()
|
||||||
|
|
||||||
void positives() {
|
void positives() {
|
||||||
if (1) BAD_MACRO(1);
|
if (1)
|
||||||
|
BAD_MACRO(1);
|
||||||
}
|
}
|
@ -2,15 +2,16 @@
|
|||||||
|
|
||||||
#include "structures.h"
|
#include "structures.h"
|
||||||
|
|
||||||
void test() {
|
void test()
|
||||||
|
{
|
||||||
// A common mistake is to swap parameters to the ‘fill’ string-constructor.
|
// A common mistake is to swap parameters to the ‘fill’ string-constructor.
|
||||||
std::string str('x', 50); // should be str(50, 'x')
|
std::string str('x', 50); // should be str(50, 'x')
|
||||||
|
|
||||||
// Calling the string-literal constructor with a length bigger than the
|
// Calling the string-literal constructor with a length bigger than the
|
||||||
// literal is suspicious and adds extra random characters to the string.
|
// literal is suspicious and adds extra random characters to the string.
|
||||||
std::string("test", 200); // Will include random characters after "test".
|
std::string("test", 200); // Will include random characters after "test".
|
||||||
|
|
||||||
// Creating an empty string from constructors with parameters is considered
|
// Creating an empty string from constructors with parameters is considered
|
||||||
// suspicious. The programmer should use the empty constructor instead.
|
// suspicious. The programmer should use the empty constructor instead.
|
||||||
std::string("test", 0); // Creation of an empty string.
|
std::string("test", 0); // Creation of an empty string.
|
||||||
}
|
}
|
||||||
|
@ -2,24 +2,27 @@
|
|||||||
|
|
||||||
#include "structures.h"
|
#include "structures.h"
|
||||||
|
|
||||||
void test_int() {
|
void test_int()
|
||||||
|
{
|
||||||
// Numeric types can be implicitly casted to character types.
|
// Numeric types can be implicitly casted to character types.
|
||||||
std::string s;
|
std::string s;
|
||||||
int x = 5965;
|
int x = 5965;
|
||||||
s = 6; // warning
|
s = 6; // warning
|
||||||
s = x; // warning
|
s = x; // warning
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_conversion() {
|
void test_conversion()
|
||||||
|
{
|
||||||
// Use the appropriate conversion functions or character literals.
|
// Use the appropriate conversion functions or character literals.
|
||||||
std::string s;
|
std::string s;
|
||||||
int x = 5965;
|
int x = 5965;
|
||||||
s = '6'; // OK
|
s = '6'; // OK
|
||||||
s = std::to_string(x); // OK
|
s = std::to_string(x); // OK
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_cast() {
|
void test_cast()
|
||||||
|
{
|
||||||
// In order to suppress false positives, use an explicit cast.
|
// In order to suppress false positives, use an explicit cast.
|
||||||
std::string s;
|
std::string s;
|
||||||
s = static_cast<char>(6); // OK
|
s = static_cast<char>(6); // OK
|
||||||
}
|
}
|
||||||
|
@ -2,20 +2,21 @@
|
|||||||
|
|
||||||
#include "structures.h"
|
#include "structures.h"
|
||||||
|
|
||||||
void test(int* ip, char* cp) {
|
void test(int* ip, char* cp)
|
||||||
|
{
|
||||||
// Case 1: Fill value is a character '0' instead of NUL '\0'.
|
// Case 1: Fill value is a character '0' instead of NUL '\0'.
|
||||||
memset(ip, '0', 1); // WARNING: suspicious for non-char pointers
|
memset(ip, '0', 1); // WARNING: suspicious for non-char pointers
|
||||||
memset(cp, '0', 1); // OK for char pointers
|
memset(cp, '0', 1); // OK for char pointers
|
||||||
|
|
||||||
// Case 2: Fill value is truncated.
|
// Case 2: Fill value is truncated.
|
||||||
memset(ip, 0xabcd, 1); // WARNING: fill value gets truncated
|
memset(ip, 0xabcd, 1); // WARNING: fill value gets truncated
|
||||||
memset(ip, 0x00cd, 1); // OK because value 0xcd is not truncated.
|
memset(ip, 0x00cd, 1); // OK because value 0xcd is not truncated.
|
||||||
memset(ip, 0x00, 1); // OK because value is not truncated.
|
memset(ip, 0x00, 1); // OK because value is not truncated.
|
||||||
|
|
||||||
// Case 3: Byte count is zero.
|
// Case 3: Byte count is zero.
|
||||||
memset(ip, sizeof(int), 0); // WARNING: zero length, potentially swapped
|
memset(ip, sizeof(int), 0); // WARNING: zero length, potentially swapped
|
||||||
memset(ip, sizeof(int), 1); // OK with non-zero length
|
memset(ip, sizeof(int), 1); // OK with non-zero length
|
||||||
|
|
||||||
// See clang bug https://bugs.llvm.org/show_bug.cgi?id=38098
|
// See clang bug https://bugs.llvm.org/show_bug.cgi?id=38098
|
||||||
memset(ip, 8, 0); // OK with zero length without sizeof
|
memset(ip, 8, 0); // OK with zero length without sizeof
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
const char* Cartoons[] = {
|
const char* Cartoons[] = {
|
||||||
"Bugs Bunny",
|
"Bugs Bunny",
|
||||||
"Homer Simpson",
|
"Homer Simpson",
|
||||||
"Mickey Mouse",
|
"Mickey Mouse",
|
||||||
"Bart Simpson",
|
"Bart Simpson",
|
||||||
"Charlie Brown" // There is a missing comma here.
|
"Charlie Brown" // There is a missing comma here.
|
||||||
"Fred Flintstone",
|
"Fred Flintstone",
|
||||||
"Popeye",
|
"Popeye",
|
||||||
};
|
};
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
|
|
||||||
// bugprone-suspicious-semicolon
|
// bugprone-suspicious-semicolon
|
||||||
void nop();
|
void nop();
|
||||||
void fail1() {
|
void fail1()
|
||||||
int x = 0;
|
{
|
||||||
if (x > 5)
|
int x = 0;
|
||||||
;
|
if(x > 5); nop();
|
||||||
nop();
|
|
||||||
}
|
}
|
||||||
|
@ -3,5 +3,6 @@ static const char A[] = "abc";
|
|||||||
int strcmp(const char *, const char *);
|
int strcmp(const char *, const char *);
|
||||||
|
|
||||||
int test_warning_patterns() {
|
int test_warning_patterns() {
|
||||||
if (strcmp(A, "a")) return 0;
|
if (strcmp(A, "a"))
|
||||||
|
return 0;
|
||||||
}
|
}
|
@ -5,21 +5,22 @@ void test_d_i_i(double d, int i, int ii);
|
|||||||
void test_i_d(int i, double d);
|
void test_i_d(int i, double d);
|
||||||
void test_i_i_d(int i, int ii, double d);
|
void test_i_i_d(int i, int ii, double d);
|
||||||
|
|
||||||
void test() {
|
void test()
|
||||||
|
{
|
||||||
double d = 1;
|
double d = 1;
|
||||||
int i = 1;
|
int i = 1;
|
||||||
|
|
||||||
test_d_i(d, i); // OK
|
test_d_i(d, i); // OK
|
||||||
test_d_i(i, d); // WARNING
|
test_d_i(i, d); // WARNING
|
||||||
|
|
||||||
test_i_d(i, d); // OK
|
test_i_d(i, d); // OK
|
||||||
test_i_d(d, i); // WARNING
|
test_i_d(d, i); // WARNING
|
||||||
|
|
||||||
test_i_i_d(i, i, d); // OK
|
test_i_i_d(i, i, d); // OK
|
||||||
test_i_i_d(i, d, i); // WARNING
|
test_i_i_d(i, d, i); // WARNING
|
||||||
test_i_i_d(d, i, i); // NO WARNING after second parameter
|
test_i_i_d(d, i, i); // NO WARNING after second parameter
|
||||||
|
|
||||||
test_d_i_i(d, i, i); // OK
|
test_d_i_i(d, i, i); // OK
|
||||||
test_d_i_i(i, d, i); // WARNING
|
test_d_i_i(i, d, i); // WARNING
|
||||||
test_d_i_i(i, i, d); // NO WARNING after second parameter
|
test_d_i_i(i, i, d); // NO WARNING after second parameter
|
||||||
}
|
}
|
||||||
|
@ -1,22 +1,25 @@
|
|||||||
// https://clang.llvm.org/extra/clang-tidy/checks/bugprone-unused-raii.html
|
// https://clang.llvm.org/extra/clang-tidy/checks/bugprone-unused-raii.html
|
||||||
|
|
||||||
struct scoped_lock {
|
struct scoped_lock
|
||||||
|
{
|
||||||
scoped_lock() {}
|
scoped_lock() {}
|
||||||
~scoped_lock() {}
|
~scoped_lock() {}
|
||||||
};
|
};
|
||||||
|
|
||||||
#define SCOPED_LOCK_MACRO(m) scoped_lock()
|
#define SCOPED_LOCK_MACRO(m) scoped_lock()
|
||||||
|
|
||||||
struct trivial_scoped_lock {
|
struct trivial_scoped_lock
|
||||||
|
{
|
||||||
trivial_scoped_lock() {}
|
trivial_scoped_lock() {}
|
||||||
};
|
};
|
||||||
|
|
||||||
scoped_lock test() {
|
scoped_lock test()
|
||||||
scoped_lock(); // misc-unused-raii warning!
|
{
|
||||||
|
scoped_lock(); // misc-unused-raii warning!
|
||||||
|
|
||||||
SCOPED_LOCK_MACRO(); // no warning for macros
|
SCOPED_LOCK_MACRO(); // no warning for macros
|
||||||
|
|
||||||
trivial_scoped_lock(); // no warning for trivial objects without destructors
|
trivial_scoped_lock(); // no warning for trivial objects without destructors
|
||||||
|
|
||||||
return scoped_lock(); // no warning for return values
|
return scoped_lock(); // no warning for return values
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ struct unique_ptr {
|
|||||||
void reset(T *ptr);
|
void reset(T *ptr);
|
||||||
T &operator*() const;
|
T &operator*() const;
|
||||||
T *operator->() const;
|
T *operator->() const;
|
||||||
T &operator[](size_t i) const;
|
T& operator[](size_t i) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename>
|
template <typename>
|
||||||
@ -34,10 +34,10 @@ template <typename _Tp>
|
|||||||
constexpr typename std::remove_reference<_Tp>::type &&move(_Tp &&__t) noexcept {
|
constexpr typename std::remove_reference<_Tp>::type &&move(_Tp &&__t) noexcept {
|
||||||
return static_cast<typename remove_reference<_Tp>::type &&>(__t);
|
return static_cast<typename remove_reference<_Tp>::type &&>(__t);
|
||||||
}
|
}
|
||||||
} // namespace std
|
}
|
||||||
|
|
||||||
class A {
|
class A {
|
||||||
public:
|
public:
|
||||||
A();
|
A();
|
||||||
A(const A &);
|
A(const A &);
|
||||||
A(A &&);
|
A(A &&);
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
void test(int z) {
|
void test(int z) {
|
||||||
if (z == 0) int x = 1 / z;
|
if (z == 0)
|
||||||
|
int x = 1 / z;
|
||||||
}
|
}
|
@ -1,5 +1,6 @@
|
|||||||
int f(int *p) __attribute__((nonnull));
|
int f(int *p) __attribute__((nonnull));
|
||||||
|
|
||||||
void test(int *p) {
|
void test(int *p) {
|
||||||
if (!p) f(p); // warn
|
if (!p)
|
||||||
|
f(p); // warn
|
||||||
}
|
}
|
@ -1,5 +1,5 @@
|
|||||||
class C {
|
class C {
|
||||||
public:
|
public:
|
||||||
int x;
|
int x;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -2,43 +2,49 @@
|
|||||||
|
|
||||||
void use(int *p);
|
void use(int *p);
|
||||||
|
|
||||||
void test_use_parameter_after_delete(int *p) {
|
void test_use_parameter_after_delete(int *p)
|
||||||
|
{
|
||||||
delete p;
|
delete p;
|
||||||
use(p); // warning: use after free
|
use(p); // warning: use after free
|
||||||
}
|
}
|
||||||
|
|
||||||
class SomeClass {
|
class SomeClass {
|
||||||
public:
|
public:
|
||||||
void f();
|
void f();
|
||||||
};
|
};
|
||||||
|
|
||||||
void test_use_local_after_delete() {
|
void test_use_local_after_delete()
|
||||||
|
{
|
||||||
SomeClass *c = new SomeClass;
|
SomeClass *c = new SomeClass;
|
||||||
delete c;
|
delete c;
|
||||||
c->f(); // warning: use after free
|
c->f(); // warning: use after free
|
||||||
}
|
}
|
||||||
|
|
||||||
// XXX clang documentation says this should cause a warning but it doesn't!
|
// XXX clang documentation says this should cause a warning but it doesn't!
|
||||||
void test_delete_alloca() {
|
void test_delete_alloca()
|
||||||
|
{
|
||||||
int *p = (int *)__builtin_alloca(sizeof(int));
|
int *p = (int *)__builtin_alloca(sizeof(int));
|
||||||
delete p; // NO warning: deleting memory allocated by alloca
|
delete p; // NO warning: deleting memory allocated by alloca
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_double_free() {
|
void test_double_free()
|
||||||
|
{
|
||||||
int *p = new int;
|
int *p = new int;
|
||||||
delete p;
|
delete p;
|
||||||
delete p; // warning: attempt to free released
|
delete p; // warning: attempt to free released
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_delete_local() {
|
void test_delete_local()
|
||||||
|
{
|
||||||
int i;
|
int i;
|
||||||
delete &i; // warning: delete address of local
|
delete &i; // warning: delete address of local
|
||||||
}
|
}
|
||||||
|
|
||||||
// XXX clang documentation says this should cause a warning but it doesn't!
|
// XXX clang documentation says this should cause a warning but it doesn't!
|
||||||
void test_delete_offset() {
|
void test_delete_offset()
|
||||||
|
{
|
||||||
int *p = new int[1];
|
int *p = new int[1];
|
||||||
delete[](++p);
|
delete[] (++p);
|
||||||
// NO warning: argument to 'delete[]' is offset by 4 bytes
|
// NO warning: argument to 'delete[]' is offset by 4 bytes
|
||||||
// from the start of memory allocated by 'new[]'
|
// from the start of memory allocated by 'new[]'
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
// https://clang-analyzer.llvm.org/available_checks.html
|
// https://clang-analyzer.llvm.org/available_checks.html
|
||||||
|
|
||||||
void test() { int *p = new int; } // warning
|
void test()
|
||||||
|
{
|
||||||
|
int *p = new int;
|
||||||
|
} // warning
|
||||||
|
@ -2,5 +2,6 @@
|
|||||||
// clang-analyzer-deadcode.DeadStores
|
// clang-analyzer-deadcode.DeadStores
|
||||||
void test() {
|
void test() {
|
||||||
int x;
|
int x;
|
||||||
x = 1; // warn
|
x = 1; // warn
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
void test() {
|
void test() {
|
||||||
for (float x = 0.1f; x <= 1.0f; x += 0.1f) {
|
for (float x = 0.1f; x <= 1.0f; x += 0.1f) {}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
#include "structures.h"
|
#include "structures.h"
|
||||||
|
|
||||||
void test() { setuid(1); }
|
void test() {
|
||||||
|
setuid(1);
|
||||||
|
}
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
#include "structures.h"
|
#include "structures.h"
|
||||||
|
|
||||||
int test_bcmp(void *a, void *b, size_t n) { return bcmp(a, b, n); }
|
int test_bcmp(void *a, void *b, size_t n) {
|
||||||
|
return bcmp(a, b, n);
|
||||||
|
}
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
#include "structures.h"
|
#include "structures.h"
|
||||||
|
|
||||||
void test_bcopy(void *a, void *b, size_t n) { bcopy(a, b, n); }
|
void test_bcopy(void *a, void *b, size_t n) {
|
||||||
|
bcopy(a, b, n);
|
||||||
|
}
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
#include "structures.h"
|
#include "structures.h"
|
||||||
|
|
||||||
void test_bzero(void *a, size_t n) { bzero(a, n); }
|
void test_bzero(void *a, size_t n) {
|
||||||
|
bzero(a, n);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
#include "structures.h"
|
#include "structures.h"
|
||||||
|
|
||||||
void test() { mkstemp("XX"); }
|
void test() {
|
||||||
|
mkstemp("XX");
|
||||||
|
}
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
#include "structures.h"
|
#include "structures.h"
|
||||||
|
|
||||||
void test() { char *x = mktemp("/tmp/zxcv"); }
|
void test() {
|
||||||
|
char *x = mktemp("/tmp/zxcv");
|
||||||
|
}
|
||||||
|
@ -1,2 +1,4 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
void test() { random(); }
|
void test() {
|
||||||
|
random();
|
||||||
|
}
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
#include "structures.h"
|
#include "structures.h"
|
||||||
|
|
||||||
void test() { vfork(); }
|
void test() {
|
||||||
|
vfork();
|
||||||
|
}
|
||||||
|
@ -2,30 +2,36 @@
|
|||||||
|
|
||||||
#include "structures.h"
|
#include "structures.h"
|
||||||
|
|
||||||
void test_malloc() {
|
void test_malloc()
|
||||||
int *p = (int *)malloc(1);
|
{
|
||||||
|
int *p = (int*) malloc(1);
|
||||||
free(p);
|
free(p);
|
||||||
free(p); // warning: attempt to free released memory
|
free(p); // warning: attempt to free released memory
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_use_after_free() {
|
void test_use_after_free()
|
||||||
int *p = (int *)malloc(sizeof(int));
|
{
|
||||||
|
int *p = (int*) malloc(sizeof(int));
|
||||||
free(p);
|
free(p);
|
||||||
*p = 1; // warning: use after free
|
*p = 1; // warning: use after free
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_leak() {
|
void test_leak()
|
||||||
int *p = (int *)malloc(1);
|
{
|
||||||
if (p) return; // warning: memory is never released
|
int *p = (int*) malloc(1);
|
||||||
|
if (p)
|
||||||
|
return; // warning: memory is never released
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_free_local() {
|
void test_free_local()
|
||||||
int a[] = {1};
|
{
|
||||||
free(a); // warning: argument is not allocated by malloc
|
int a[] = { 1 };
|
||||||
|
free(a); // warning: argument is not allocated by malloc
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_free_offset() {
|
void test_free_offset()
|
||||||
int *p = (int *)malloc(sizeof(char));
|
{
|
||||||
|
int *p = (int*) malloc(sizeof(char));
|
||||||
p = p - 1;
|
p = p - 1;
|
||||||
free(p); // warning: argument to free() is offset by -4 bytes
|
free(p); // warning: argument to free() is offset by -4 bytes
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,8 @@
|
|||||||
|
|
||||||
#include "structures.h"
|
#include "structures.h"
|
||||||
|
|
||||||
void test() {
|
void test()
|
||||||
|
{
|
||||||
char dest[3];
|
char dest[3];
|
||||||
strncat(dest, "***", sizeof(dest)); // warning : potential buffer overflow
|
strncat(dest, "***", sizeof(dest)); // warning : potential buffer overflow
|
||||||
}
|
}
|
||||||
|
@ -2,11 +2,13 @@
|
|||||||
|
|
||||||
#include "structures.h"
|
#include "structures.h"
|
||||||
|
|
||||||
int my_strlen(const char* s) {
|
int my_strlen(const char* s)
|
||||||
return strlen(s); // warning
|
{
|
||||||
|
return strlen(s); // warning
|
||||||
}
|
}
|
||||||
|
|
||||||
int bad_caller() {
|
int bad_caller()
|
||||||
|
{
|
||||||
const char* s = nullptr;
|
const char* s = nullptr;
|
||||||
return my_strlen(s);
|
return my_strlen(s);
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
namespace std {
|
namespace std {
|
||||||
typedef struct FILE {
|
typedef struct FILE {} FILE;
|
||||||
} FILE;
|
}
|
||||||
} // namespace std
|
|
||||||
|
|
||||||
void g(std::FILE f);
|
void g(std::FILE f);
|
@ -1,15 +1,18 @@
|
|||||||
// https://clang.llvm.org/extra/clang-tidy/checks/misc-unused-alias-decls.html
|
// https://clang.llvm.org/extra/clang-tidy/checks/misc-unused-alias-decls.html
|
||||||
|
|
||||||
namespace n1 {
|
namespace n1 {
|
||||||
namespace n2 {
|
namespace n2 {
|
||||||
namespace n3 {
|
namespace n3 {
|
||||||
int qux = 42;
|
int qux = 42;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} // namespace n2
|
|
||||||
} // namespace n1
|
|
||||||
|
|
||||||
namespace n1_unused = ::n1; // WARNING
|
namespace n1_unused = ::n1; // WARNING
|
||||||
namespace n12_unused = n1::n2; // WARNING
|
namespace n12_unused = n1::n2; // WARNING
|
||||||
namespace n123 = n1::n2::n3; // OK
|
namespace n123 = n1::n2::n3; // OK
|
||||||
|
|
||||||
int test() { return n123::qux; }
|
int test()
|
||||||
|
{
|
||||||
|
return n123::qux;
|
||||||
|
}
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
|
|
||||||
// misc-unused-using-decls
|
// misc-unused-using-decls
|
||||||
namespace n {
|
namespace n { class C; }
|
||||||
class C;
|
|
||||||
}
|
|
||||||
using n::C;
|
using n::C;
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
#include "structures.h"
|
#include "structures.h"
|
||||||
|
|
||||||
int add(int x, int y) { return x + y; }
|
int add(int x, int y) { return x + y; }
|
||||||
void f_bind() { auto clj = std::bind(add, 2, 2); }
|
void f_bind() {
|
||||||
|
auto clj = std::bind(add, 2, 2);
|
||||||
|
}
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
// modernize-redundant-void-arg
|
// modernize-redundant-void-arg
|
||||||
|
|
||||||
int foo(void) { return 0; }
|
int foo(void) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
@ -5,6 +5,7 @@ void func() {
|
|||||||
std::vector<int> my_container;
|
std::vector<int> my_container;
|
||||||
for (std::vector<int>::iterator I = my_container.begin(),
|
for (std::vector<int>::iterator I = my_container.begin(),
|
||||||
E = my_container.end();
|
E = my_container.end();
|
||||||
I != E; ++I) {
|
I != E;
|
||||||
|
++I) {
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,6 +1,6 @@
|
|||||||
|
|
||||||
class IL {
|
class IL {
|
||||||
public:
|
public:
|
||||||
IL() {}
|
IL() {}
|
||||||
~IL() {}
|
~IL() {}
|
||||||
};
|
};
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
struct PositivePrivate {
|
struct PositivePrivate {
|
||||||
private:
|
private:
|
||||||
PositivePrivate();
|
PositivePrivate();
|
||||||
PositivePrivate(const PositivePrivate &);
|
PositivePrivate(const PositivePrivate &);
|
||||||
PositivePrivate &operator=(PositivePrivate &&);
|
PositivePrivate &operator=(PositivePrivate &&);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#define NULL 0
|
#define NULL 0
|
||||||
void f(void) {
|
void f(void) {
|
||||||
char *str = NULL; // ok
|
char *str = NULL; // ok
|
||||||
(void)str;
|
(void)str;
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
class Base {
|
class Base {
|
||||||
public:
|
public:
|
||||||
virtual void foo() = 0;
|
virtual void foo() = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
struct Iterator {
|
struct Iterator {
|
||||||
void operator++() {}
|
void operator++() {}
|
||||||
const T &operator*() {
|
const T& operator*() {
|
||||||
static T *TT = new T();
|
static T* TT = new T();
|
||||||
return *TT;
|
return *TT;
|
||||||
}
|
}
|
||||||
bool operator!=(const Iterator &) { return false; }
|
bool operator!=(const Iterator &) { return false; }
|
||||||
typedef const T &const_reference;
|
typedef const T& const_reference;
|
||||||
};
|
};
|
||||||
template <typename T>
|
template <typename T>
|
||||||
struct View {
|
struct View {
|
||||||
|
@ -37,10 +37,7 @@ struct SimpleClass {
|
|||||||
typedef View<Iterator<SimpleClass>> SimpleView;
|
typedef View<Iterator<SimpleClass>> SimpleView;
|
||||||
|
|
||||||
void ImplicitSimpleClassIterator() {
|
void ImplicitSimpleClassIterator() {
|
||||||
for (const ImplicitWrapper<SimpleClass>& foo : SimpleView()) {
|
for (const ImplicitWrapper<SimpleClass>& foo : SimpleView()) {}
|
||||||
}
|
for (const ImplicitWrapper<SimpleClass> foo : SimpleView()) {}
|
||||||
for (const ImplicitWrapper<SimpleClass> foo : SimpleView()) {
|
for (ImplicitWrapper<SimpleClass> foo : SimpleView()) {}
|
||||||
}
|
|
||||||
for (ImplicitWrapper<SimpleClass> foo : SimpleView()) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,18 +1,15 @@
|
|||||||
namespace std {
|
namespace std {
|
||||||
template <typename T>
|
template <typename T> struct less {
|
||||||
struct less {
|
|
||||||
bool operator()(const T &lhs, const T &rhs) { return lhs < rhs; }
|
bool operator()(const T &lhs, const T &rhs) { return lhs < rhs; }
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T> struct greater {
|
||||||
struct greater {
|
|
||||||
bool operator()(const T &lhs, const T &rhs) { return lhs > rhs; }
|
bool operator()(const T &lhs, const T &rhs) { return lhs > rhs; }
|
||||||
};
|
};
|
||||||
|
|
||||||
struct iterator_type {};
|
struct iterator_type {};
|
||||||
|
|
||||||
template <typename K, typename Cmp = less<K>>
|
template <typename K, typename Cmp = less<K>> struct set {
|
||||||
struct set {
|
|
||||||
typedef iterator_type iterator;
|
typedef iterator_type iterator;
|
||||||
iterator find(const K &k);
|
iterator find(const K &k);
|
||||||
unsigned count(const K &k);
|
unsigned count(const K &k);
|
||||||
@ -24,13 +21,10 @@ struct set {
|
|||||||
};
|
};
|
||||||
|
|
||||||
template <typename FwIt, typename K>
|
template <typename FwIt, typename K>
|
||||||
FwIt find(FwIt, FwIt end, const K &) {
|
FwIt find(FwIt, FwIt end, const K &) { return end; }
|
||||||
return end;
|
|
||||||
}
|
}
|
||||||
} // namespace std
|
|
||||||
|
|
||||||
template <typename T>
|
template <typename T> void f(const T &t) {
|
||||||
void f(const T &t) {
|
|
||||||
std::set<int> s;
|
std::set<int> s;
|
||||||
find(s.begin(), s.end(), 46);
|
find(s.begin(), s.end(), 46);
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#include "structures.h"
|
#include "structures.h"
|
||||||
|
|
||||||
void foo() {
|
void foo()
|
||||||
|
{
|
||||||
std::vector<int> v;
|
std::vector<int> v;
|
||||||
int n = 100;
|
int n = 100;
|
||||||
for (int i = 0; i < n; ++i) {
|
for (int i = 0; i < n; ++i) {
|
||||||
|
@ -8,7 +8,7 @@ template <typename _Tp>
|
|||||||
constexpr typename std::remove_reference<_Tp>::type &&move(_Tp &&__t) {
|
constexpr typename std::remove_reference<_Tp>::type &&move(_Tp &&__t) {
|
||||||
return static_cast<typename std::remove_reference<_Tp>::type &&>(__t);
|
return static_cast<typename std::remove_reference<_Tp>::type &&>(__t);
|
||||||
}
|
}
|
||||||
} // namespace std
|
} // namespace std
|
||||||
|
|
||||||
struct TriviallyCopyable {
|
struct TriviallyCopyable {
|
||||||
int i;
|
int i;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
struct B {
|
struct B {
|
||||||
B() {}
|
B() {}
|
||||||
B(const B &) {}
|
B(const B&) {}
|
||||||
B(B &&) {}
|
B(B &&) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
double acos(double);
|
double acos(double);
|
||||||
|
|
||||||
void check_all_fns() {
|
void check_all_fns()
|
||||||
|
{
|
||||||
float a;
|
float a;
|
||||||
acos(a);
|
acos(a);
|
||||||
}
|
}
|
@ -2,4 +2,6 @@
|
|||||||
|
|
||||||
extern const std::string& constReference();
|
extern const std::string& constReference();
|
||||||
|
|
||||||
void foo() { const std::string UnnecessaryCopy = constReference(); }
|
void foo() {
|
||||||
|
const std::string UnnecessaryCopy = constReference();
|
||||||
|
}
|
@ -1,3 +1,4 @@
|
|||||||
#include "structures.h"
|
#include "structures.h"
|
||||||
|
|
||||||
void f(const std::string Value) {}
|
void f(const std::string Value) {
|
||||||
|
}
|
@ -1,17 +1,14 @@
|
|||||||
|
|
||||||
void do_something(const char *) {}
|
void do_something(const char *) {}
|
||||||
|
|
||||||
bool cond(const char *) { return false; }
|
bool cond(const char *) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
void test() {
|
void test() {
|
||||||
if (cond("if0") /*comment*/) do_something("same-line");
|
if (cond("if0") /*comment*/) do_something("same-line");
|
||||||
}
|
}
|
||||||
|
|
||||||
void foo() {
|
void foo() {
|
||||||
if (1)
|
if (1) while (2) if (3) for (;;) do ; while(false) /**/;/**/
|
||||||
while (2)
|
|
||||||
if (3)
|
|
||||||
for (;;) do
|
|
||||||
;
|
|
||||||
while (false) /**/; /**/
|
|
||||||
}
|
}
|
||||||
|
@ -2,5 +2,6 @@
|
|||||||
|
|
||||||
void foo() {
|
void foo() {
|
||||||
std::string a;
|
std::string a;
|
||||||
if (a.size()) return;
|
if (a.size())
|
||||||
|
return;
|
||||||
}
|
}
|
@ -1,4 +1,6 @@
|
|||||||
void f() {}
|
void f() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void foo() {
|
void foo() {
|
||||||
if (true)
|
if (true)
|
||||||
|
@ -43,19 +43,13 @@ void f() {
|
|||||||
|
|
||||||
int exp = (int)true;
|
int exp = (int)true;
|
||||||
|
|
||||||
if (x == b) {
|
if (x == b) {}
|
||||||
}
|
if (x != b) {}
|
||||||
if (x != b) {
|
|
||||||
}
|
|
||||||
|
|
||||||
if (b == exp) {
|
if (b == exp) {}
|
||||||
}
|
if (exp == b) {}
|
||||||
if (exp == b) {
|
|
||||||
}
|
|
||||||
|
|
||||||
char* ptr;
|
char* ptr;
|
||||||
// Shouldn't trigger a checker warning since we are using
|
// Shouldn't trigger a checker warning since we are using AllowPointerConditions
|
||||||
// AllowPointerConditions
|
if (ptr) {}
|
||||||
if (ptr) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -2,4 +2,5 @@ struct S {
|
|||||||
void f(int x);
|
void f(int x);
|
||||||
};
|
};
|
||||||
|
|
||||||
void S::f(int y) {}
|
void S::f(int y) {
|
||||||
|
}
|
@ -1,9 +1,11 @@
|
|||||||
void f() {}
|
void f()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
void foo() {
|
void foo() {
|
||||||
if (1)
|
if (1)
|
||||||
if (0)
|
if (0)
|
||||||
f();
|
f();
|
||||||
else
|
else
|
||||||
f();
|
f();
|
||||||
}
|
}
|
@ -9,8 +9,12 @@ struct unique_ptr {
|
|||||||
T* get() const;
|
T* get() const;
|
||||||
explicit operator bool() const noexcept;
|
explicit operator bool() const noexcept;
|
||||||
};
|
};
|
||||||
} // namespace std
|
}
|
||||||
|
|
||||||
struct A {};
|
struct A {
|
||||||
|
};
|
||||||
|
|
||||||
|
void foo() {
|
||||||
|
A& b2 = *std::unique_ptr<A>().get();
|
||||||
|
}
|
||||||
|
|
||||||
void foo() { A& b2 = *std::unique_ptr<A>().get(); }
|
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
#include "structures.h"
|
#include "structures.h"
|
||||||
|
|
||||||
int foo() { std::string a = ""; }
|
int foo() {
|
||||||
|
std::string a = "";
|
||||||
|
}
|
@ -6,4 +6,6 @@ int C::x = 0;
|
|||||||
|
|
||||||
// Expressions with side effects
|
// Expressions with side effects
|
||||||
C &f(int, int, int, int);
|
C &f(int, int, int, int);
|
||||||
void g() { f(1, 2, 3, 4).x; }
|
void g() {
|
||||||
|
f(1, 2, 3, 4).x;
|
||||||
|
}
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
// Proxy file in order to define generic data types, to avoid binding with
|
// Proxy file in order to define generic data types, to avoid binding with system headers
|
||||||
// system headers
|
|
||||||
|
|
||||||
typedef __SIZE_TYPE__ size_t;
|
typedef __SIZE_TYPE__ size_t;
|
||||||
|
|
||||||
@ -10,27 +9,26 @@ typedef size_t size_t;
|
|||||||
template <class T>
|
template <class T>
|
||||||
class vector {
|
class vector {
|
||||||
public:
|
public:
|
||||||
typedef T *iterator;
|
typedef T* iterator;
|
||||||
typedef const T *const_iterator;
|
typedef const T* const_iterator;
|
||||||
typedef T &reference;
|
typedef T& reference;
|
||||||
typedef const T &const_reference;
|
typedef const T& const_reference;
|
||||||
typedef size_t size_type;
|
typedef size_t size_type;
|
||||||
|
|
||||||
explicit vector();
|
explicit vector();
|
||||||
explicit vector(size_type n);
|
explicit vector(size_type n);
|
||||||
|
|
||||||
void swap(vector &other);
|
void swap(vector &other);
|
||||||
void push_back(const T &val);
|
void push_back(const T& val);
|
||||||
|
|
||||||
template <class... Args>
|
template <class... Args> void emplace_back(Args &&... args);
|
||||||
void emplace_back(Args &&... args);
|
|
||||||
|
|
||||||
void reserve(size_t n);
|
void reserve(size_t n);
|
||||||
void resize(size_t n);
|
void resize(size_t n);
|
||||||
|
|
||||||
size_t size();
|
size_t size();
|
||||||
const_reference operator[](size_type) const;
|
const_reference operator[] (size_type) const;
|
||||||
reference operator[](size_type);
|
reference operator[] (size_type);
|
||||||
|
|
||||||
const_iterator begin() const;
|
const_iterator begin() const;
|
||||||
const_iterator end() const;
|
const_iterator end() const;
|
||||||
@ -38,7 +36,7 @@ class vector {
|
|||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
class basic_string {
|
class basic_string {
|
||||||
public:
|
public:
|
||||||
typedef basic_string<T> _Type;
|
typedef basic_string<T> _Type;
|
||||||
basic_string() {}
|
basic_string() {}
|
||||||
basic_string(const T *p);
|
basic_string(const T *p);
|
||||||
@ -47,13 +45,12 @@ class basic_string {
|
|||||||
~basic_string() {}
|
~basic_string() {}
|
||||||
size_t size() const;
|
size_t size() const;
|
||||||
bool empty() const;
|
bool empty() const;
|
||||||
size_t find(const char *s, size_t pos = 0) const;
|
size_t find (const char* s, size_t pos = 0) const;
|
||||||
const T *c_str() const;
|
const T *c_str() const;
|
||||||
_Type &assign(const T *s);
|
_Type& assign(const T *s);
|
||||||
basic_string<T> &operator=(T ch);
|
basic_string<T> &operator=(T ch);
|
||||||
basic_string<T> *operator+=(const basic_string<T> &) {}
|
basic_string<T> *operator+=(const basic_string<T> &) {}
|
||||||
friend basic_string<T> operator+(const basic_string<T> &,
|
friend basic_string<T> operator+(const basic_string<T> &, const basic_string<T> &) {}
|
||||||
const basic_string<T> &) {}
|
|
||||||
};
|
};
|
||||||
typedef basic_string<char> string;
|
typedef basic_string<char> string;
|
||||||
typedef basic_string<wchar_t> wstring;
|
typedef basic_string<wchar_t> wstring;
|
||||||
@ -68,10 +65,10 @@ class unique_ptr {
|
|||||||
public:
|
public:
|
||||||
unique_ptr();
|
unique_ptr();
|
||||||
~unique_ptr();
|
~unique_ptr();
|
||||||
explicit unique_ptr(T *);
|
explicit unique_ptr(T*);
|
||||||
template <typename U, typename E>
|
template <typename U, typename E>
|
||||||
unique_ptr(unique_ptr<U, E> &&);
|
unique_ptr(unique_ptr<U, E>&&);
|
||||||
T *release();
|
T* release();
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class Fp, class... Arguments>
|
template <class Fp, class... Arguments>
|
||||||
@ -79,7 +76,7 @@ class bind_rt {};
|
|||||||
|
|
||||||
template <class Fp, class... Arguments>
|
template <class Fp, class... Arguments>
|
||||||
bind_rt<Fp, Arguments...> bind(Fp &&, Arguments &&...);
|
bind_rt<Fp, Arguments...> bind(Fp &&, Arguments &&...);
|
||||||
} // namespace std
|
}
|
||||||
|
|
||||||
typedef unsigned int uid_t;
|
typedef unsigned int uid_t;
|
||||||
typedef unsigned int pid_t;
|
typedef unsigned int pid_t;
|
||||||
@ -98,8 +95,9 @@ pid_t vfork(void);
|
|||||||
|
|
||||||
int abort() { return 0; }
|
int abort() { return 0; }
|
||||||
|
|
||||||
#define assert(x) \
|
#define assert(x) \
|
||||||
if (!(x)) (void)abort()
|
if (!(x)) \
|
||||||
|
(void)abort()
|
||||||
|
|
||||||
size_t strlen(const char *s);
|
size_t strlen(const char *s);
|
||||||
char *strncat(char *s1, const char *s2, size_t);
|
char *strncat(char *s1, const char *s2, size_t);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user