Skip to content

Commit

Permalink
fixed readability-redundant-string-cstr clang-tidy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
firewave committed May 4, 2024
1 parent 96fc444 commit a2937f8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion test/testtoken.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class TestToken : public TestFixture {
SimpleTokenizer tokenizer(settingsDefault, *this);
const std::string code2 = ";" + code + ";";
try {
ASSERT_LOC(tokenizer.tokenize(code2.c_str()), file, line);
ASSERT_LOC(tokenizer.tokenize(code2), file, line);
} catch (...) {}
return Token::Match(tokenizer.tokens()->next(), pattern.c_str(), varid);
}
Expand Down
4 changes: 2 additions & 2 deletions test/testtokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -931,7 +931,7 @@ class TestTokenizer : public TestFixture {

void longtok() {
const std::string filedata(10000, 'a');
ASSERT_EQUALS(filedata, tokenizeAndStringify(filedata.c_str()));
ASSERT_EQUALS(filedata, tokenizeAndStringify(filedata));
}


Expand Down Expand Up @@ -6934,7 +6934,7 @@ class TestTokenizer : public TestFixture {
const std::string filedata = tokens1.stringify();
const std::string code = PreprocessorHelper::getcode(settings0, *this, filedata, emptyString, emptyString);

ASSERT_THROW_INTERNAL(tokenizeAndStringify(code.c_str()), AST);
ASSERT_THROW_INTERNAL(tokenizeAndStringify(code), AST);
}

#define isStartOfExecutableScope(offset, code) isStartOfExecutableScope_(offset, code, __FILE__, __LINE__)
Expand Down
20 changes: 10 additions & 10 deletions test/testtype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,13 @@ class TestType : public TestFixture {
{
const std::string types[] = {"unsigned char", /*[unsigned]*/ "char", "bool", "unsigned short", "unsigned int", "unsigned long"};
for (const std::string& type : types) {
check((type + " f(" + type +" x) { return x << 31; }").c_str(), settings);
check(type + " f(" + type +" x) { return x << 31; }", settings);
ASSERT_EQUALS("", errout_str());
check((type + " f(" + type +" x) { return x << 33; }").c_str(), settings);
check(type + " f(" + type +" x) { return x << 33; }", settings);
ASSERT_EQUALS("[test.cpp:1]: (error) Shifting 32-bit value by 33 bits is undefined behaviour\n", errout_str());
check((type + " f(int x) { return (x = (" + type + ")x << 32); }").c_str(), settings);
check(type + " f(int x) { return (x = (" + type + ")x << 32); }", settings);
ASSERT_EQUALS("[test.cpp:1]: (error) Shifting 32-bit value by 32 bits is undefined behaviour\n", errout_str());
check((type + " foo(" + type + " x) { return x << 31; }").c_str(), settings);
check(type + " foo(" + type + " x) { return x << 31; }", settings);
ASSERT_EQUALS("", errout_str());
}
}
Expand All @@ -113,19 +113,19 @@ class TestType : public TestFixture {
const std::string types[] = {"signed char", "signed short", /*[signed]*/ "short", "wchar_t", /*[signed]*/ "int", "signed int", /*[signed]*/ "long", "signed long"};
for (const std::string& type : types) {
// c++11
check((type + " f(" + type +" x) { return x << 33; }").c_str(), settings);
check(type + " f(" + type +" x) { return x << 33; }", settings);
ASSERT_EQUALS("[test.cpp:1]: (error) Shifting 32-bit value by 33 bits is undefined behaviour\n", errout_str());
check((type + " f(int x) { return (x = (" + type + ")x << 32); }").c_str(), settings);
check(type + " f(int x) { return (x = (" + type + ")x << 32); }", settings);
ASSERT_EQUALS("[test.cpp:1]: (error) Shifting 32-bit value by 32 bits is undefined behaviour\n", errout_str());
check((type + " foo(" + type + " x) { return x << 31; }").c_str(), settings);
check(type + " foo(" + type + " x) { return x << 31; }", settings);
ASSERT_EQUALS("[test.cpp:1]: (error) Shifting signed 32-bit value by 31 bits is undefined behaviour\n", errout_str());
check((type + " foo(" + type + " x) { return x << 30; }").c_str(), settings);
check(type + " foo(" + type + " x) { return x << 30; }", settings);
ASSERT_EQUALS("", errout_str());

// c++14
check((type + " foo(" + type + " x) { return x << 31; }").c_str(), settings, true, Standards::cppstd_t::CPP14);
check(type + " foo(" + type + " x) { return x << 31; }", settings, true, Standards::cppstd_t::CPP14);
ASSERT_EQUALS("[test.cpp:1]: (portability) Shifting signed 32-bit value by 31 bits is implementation-defined behaviour\n", errout_str());
check((type + " f(int x) { return (x = (" + type + ")x << 32); }").c_str(), settings, true, Standards::cppstd_t::CPP14);
check(type + " f(int x) { return (x = (" + type + ")x << 32); }", settings, true, Standards::cppstd_t::CPP14);
ASSERT_EQUALS("[test.cpp:1]: (error) Shifting 32-bit value by 32 bits is undefined behaviour\n", errout_str());
}
}
Expand Down

0 comments on commit a2937f8

Please sign in to comment.