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 16, 2024
1 parent a294535 commit 088beb6
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 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
2 changes: 1 addition & 1 deletion test/testunusedfunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@ class TestUnusedFunctions : public TestFixture {
const char code[] = R"(#include "test.h")";
ScopedFile header("test.h", inc);
const std::string processed = PreprocessorHelper::getcode(settings, *this, code, "", "test.cpp");
check(processed.c_str());
check(processed);
TODO_ASSERT_EQUALS("[test.h:3]: (style) The function 'f' is never used.\n", "[test.cpp:3]: (style) The function 'f' is never used.\n", errout_str());
}
};
Expand Down

0 comments on commit 088beb6

Please sign in to comment.