Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions test/testbufferoverrun.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ class TestBufferOverrun : public TestFixture {
}

#define checkP(...) checkP_(__FILE__, __LINE__, __VA_ARGS__)
void checkP_(const char* file, int line, const char code[], const char* filename = "test.cpp")
void checkP_(const char* file, int line, const char code[])
{
const Settings settings = settingsBuilder(settings0).severity(Severity::performance).certainty(Certainty::inconclusive).build();

std::vector<std::string> files(1, filename);
std::vector<std::string> files(1, "test.cpp");
Tokenizer tokenizer(settings, *this);
PreprocessorHelper::preprocess(code, files, tokenizer, *this);

Expand Down
6 changes: 3 additions & 3 deletions test/testcondition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,15 @@ class TestCondition : public TestFixture {
{
CheckOptions() = default;
const Settings* s = nullptr;
const char* filename = "test.cpp";
bool cpp = true;
bool inconclusive = false;
};

#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)
void check_(const char* file, int line, const char code[], const CheckOptions& options = make_default_obj()) {
const Settings settings = settingsBuilder(options.s ? *options.s : settings0).certainty(Certainty::inconclusive, options.inconclusive).build();
Tokenizer tokenizer(settings, *this);
std::vector<std::string> files(1, options.filename);
std::vector<std::string> files(1, options.cpp ? "test.cpp" : "test.c");
PreprocessorHelper::preprocess(code, files, tokenizer, *this);

// Tokenizer..
Expand Down Expand Up @@ -3162,7 +3162,7 @@ class TestCondition : public TestFixture {
check("void f() { A<x &> a; }");
ASSERT_EQUALS("", errout_str());

check("void f() { a(x<y|z,0); }", dinit(CheckOptions, $.filename = "test.c")); // filename is c => there are never templates
check("void f() { a(x<y|z,0); }", dinit(CheckOptions, $.cpp = false)); // language is c => there are never templates
ASSERT_EQUALS("[test.c:1]: (style) Boolean result is used in bitwise operation. Clarify expression with parentheses.\n", errout_str());

check("class A<B&,C>;");
Expand Down
14 changes: 10 additions & 4 deletions test/testother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,9 +336,15 @@ class TestOther : public TestFixture {
check_(file, line, code, true, true, true, false, s);
}

struct CheckPOptions
{
CheckPOptions() = default;
bool cpp = true;
};

#define checkP(...) checkP_(__FILE__, __LINE__, __VA_ARGS__)
template<size_t size>
void checkP_(const char* file, int line, const char (&code)[size], const char *filename = "test.cpp") {
void checkP_(const char* file, int line, const char (&code)[size], const CheckPOptions& options = make_default_obj()) {
Settings* settings = &_settings;
settings->severity.enable(Severity::style);
settings->severity.enable(Severity::warning);
Expand All @@ -348,7 +354,7 @@ class TestOther : public TestFixture {
settings->standards.cpp = Standards::CPPLatest;
settings->certainty.enable(Certainty::inconclusive);

std::vector<std::string> files(1, filename);
std::vector<std::string> files(1, options.cpp ? "test.cpp" : "test.c");
Tokenizer tokenizer(*settings, *this);
PreprocessorHelper::preprocess(code, files, tokenizer, *this);

Expand Down Expand Up @@ -5601,7 +5607,7 @@ class TestOther : public TestFixture {
" }\n"
" OUTB(index, port_0);\n"
" return INB(port_1);\n"
"}\n", "test.c");
"}\n", dinit(CheckPOptions, $.cpp = false));
ASSERT_EQUALS("", errout_str());

check("[[noreturn]] void n();\n"
Expand Down Expand Up @@ -11672,7 +11678,7 @@ class TestOther : public TestFixture {
checkP("#define X x\n"
"void f(int x) {\n"
" return x + X++;\n"
"}", "test.c");
"}", dinit(CheckPOptions, $.cpp = false));
ASSERT_EQUALS("[test.c:3]: (error) Expression 'x+x++' depends on order of evaluation of side effects\n", errout_str());
}

Expand Down
22 changes: 11 additions & 11 deletions test/teststring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ class TestString : public TestFixture {
struct CheckOptions
{
CheckOptions() = default;
const char* filename = "test.cpp";
bool cpp = true;
};

#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)
void check_(const char* file, int line, const char code[], const CheckOptions& options = make_default_obj()) {
std::vector<std::string> files(1, options.filename);
std::vector<std::string> files(1, options.cpp ? "test.cpp" : "test.c");
Tokenizer tokenizer(settings, *this);
PreprocessorHelper::preprocess(code, files, tokenizer, *this);

Expand Down Expand Up @@ -337,7 +337,7 @@ class TestString : public TestFixture {

check("bool foo(char* c) {\n"
" return \"x\" == c+foo;\n"
"}", dinit(CheckOptions, $.filename = "test.c"));
"}", dinit(CheckOptions, $.cpp = false));
ASSERT_EQUALS("[test.c:2]: (warning) String literal compared with variable 'c+foo'. Did you intend to use strcmp() instead?\n", errout_str());

check("bool foo(Foo c) {\n"
Expand All @@ -347,7 +347,7 @@ class TestString : public TestFixture {

check("bool foo(Foo c) {\n"
" return \"x\" == c.foo;\n"
"}", dinit(CheckOptions, $.filename = "test.c"));
"}", dinit(CheckOptions, $.cpp = false));
ASSERT_EQUALS("[test.c:2]: (warning) String literal compared with variable 'c.foo'. Did you intend to use strcmp() instead?\n", errout_str());

check("bool foo(const std::string& c) {\n"
Expand All @@ -363,7 +363,7 @@ class TestString : public TestFixture {
// Ticket #4257
check("bool foo() {\n"
"MyString *str=Getter();\n"
"return *str==\"bug\"; }\n", dinit(CheckOptions, $.filename = "test.c"));
"return *str==\"bug\"; }\n", dinit(CheckOptions, $.cpp = false));
ASSERT_EQUALS("[test.c:3]: (warning) String literal compared with variable '*str'. Did you intend to use strcmp() instead?\n", errout_str());

// Ticket #4257
Expand All @@ -375,27 +375,27 @@ class TestString : public TestFixture {
// Ticket #4257
check("bool foo() {\n"
"MyString **str=OtherGetter();\n"
"return *str==\"bug\"; }", dinit(CheckOptions, $.filename = "test.c"));
"return *str==\"bug\"; }", dinit(CheckOptions, $.cpp = false));
ASSERT_EQUALS("[test.c:3]: (warning) String literal compared with variable '*str'. Did you intend to use strcmp() instead?\n", errout_str());

// Ticket #4257
check("bool foo() {\n"
"MyString str=OtherGetter2();\n"
"return &str==\"bug\"; }", dinit(CheckOptions, $.filename = "test.c"));
"return &str==\"bug\"; }", dinit(CheckOptions, $.cpp = false));
ASSERT_EQUALS("[test.c:3]: (warning) String literal compared with variable '&str'. Did you intend to use strcmp() instead?\n", errout_str());

// Ticket #5734
check("int foo(char c) {\n"
"return c == '4';}");
ASSERT_EQUALS("", errout_str());
check("int foo(char c) {\n"
"return c == '4';}", dinit(CheckOptions, $.filename = "test.c"));
"return c == '4';}", dinit(CheckOptions, $.cpp = false));
ASSERT_EQUALS("", errout_str());
check("int foo(char c) {\n"
"return c == \"42\"[0];}");
ASSERT_EQUALS("", errout_str());
check("int foo(char c) {\n"
"return c == \"42\"[0];}", dinit(CheckOptions, $.filename = "test.c"));
"return c == \"42\"[0];}", dinit(CheckOptions, $.cpp = false));
ASSERT_EQUALS("", errout_str());

// 5639 String literal compared with char buffer in a struct
Expand All @@ -413,7 +413,7 @@ class TestString : public TestFixture {
"void foo() {\n"
" struct Example example;\n"
" if (example.buffer == \"test\") ;\n"
"}\n", dinit(CheckOptions, $.filename = "test.c"));
"}\n", dinit(CheckOptions, $.cpp = false));
ASSERT_EQUALS("[test.c:6]: (warning) String literal compared with variable 'example.buffer'. Did you intend to use strcmp() instead?\n", errout_str());

// #9726
Expand Down Expand Up @@ -467,7 +467,7 @@ class TestString : public TestFixture {

check("bool foo(char* c) {\n"
" return *c == 0;\n"
"}", dinit(CheckOptions, $.filename = "test.c"));
"}", dinit(CheckOptions, $.cpp = false));
ASSERT_EQUALS("", errout_str());

check("bool foo(char* c) {\n"
Expand Down
8 changes: 4 additions & 4 deletions test/testtype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,15 @@ class TestType : public TestFixture {
struct CheckPOptions
{
CheckPOptions() = default;
const char* filename = "test.cpp";
bool cpp = true;
};

#define checkP(...) checkP_(__FILE__, __LINE__, __VA_ARGS__)
template<size_t size>
void checkP_(const char* file, int line, const char (&code)[size], const Settings& settings, const CheckPOptions& options = make_default_obj()) {
const Settings settings1 = settingsBuilder(settings).severity(Severity::warning).severity(Severity::portability).build();

std::vector<std::string> files(1, options.filename);
std::vector<std::string> files(1, options.cpp ? "test.cpp" : "test.c");
Tokenizer tokenizer(settings1, *this);
PreprocessorHelper::preprocess(code, files, tokenizer, *this);

Expand Down Expand Up @@ -566,14 +566,14 @@ class TestType : public TestFixture {
"void f()\n"
"{\n"
" unsigned short u = TEST(true, 75000.0);\n"
"}\n", settingsDefault, dinit(CheckPOptions, $.filename = "test.c"));
"}\n", settingsDefault, dinit(CheckPOptions, $.cpp = false));
ASSERT_EQUALS("", errout_str());

checkP("#define TEST(b, f) b ? 5000 : (unsigned short)f\n"
"void f()\n"
"{\n"
" unsigned short u = TEST(false, 75000.0);\n"
"}\n", settingsDefault, dinit(CheckPOptions, $.filename = "test.c"));
"}\n", settingsDefault, dinit(CheckPOptions, $.cpp = false));
ASSERT_EQUALS("[test.c:4]: (error) Undefined behaviour: float () to integer conversion overflow.\n", removeFloat(errout_str()));

}
Expand Down
4 changes: 2 additions & 2 deletions test/testvarid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,8 @@ class TestVarID : public TestFixture {

#define tokenizeExpr(...) tokenizeExpr_(__FILE__, __LINE__, __VA_ARGS__)
template<size_t size>
std::string tokenizeExpr_(const char* file, int line, const char (&code)[size], const char filename[] = "test.cpp") {
std::vector<std::string> files(1, filename);
std::string tokenizeExpr_(const char* file, int line, const char (&code)[size]) {
std::vector<std::string> files(1, "test.cpp");
Tokenizer tokenizer(settings, *this);
PreprocessorHelper::preprocess(code, files, tokenizer, *this);

Expand Down
Loading