From e0ad26747fb02541c5ba7f9a3e699bca2e5c174d Mon Sep 17 00:00:00 2001 From: firewave Date: Sat, 4 May 2024 15:02:34 +0200 Subject: [PATCH] fixed `readability-redundant-string-cstr` clang-tidy warnings --- test/testtoken.cpp | 2 +- test/testtokenize.cpp | 4 ++-- test/testtype.cpp | 20 ++++++++++---------- test/testunusedfunctions.cpp | 2 +- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/test/testtoken.cpp b/test/testtoken.cpp index c13fd873bdc9..937b5bf57cdd 100644 --- a/test/testtoken.cpp +++ b/test/testtoken.cpp @@ -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); } diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index dcbe7e9b71a1..d470035a2f50 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -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)); } @@ -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__) diff --git a/test/testtype.cpp b/test/testtype.cpp index f619dd48a10a..d00b52dd52da 100644 --- a/test/testtype.cpp +++ b/test/testtype.cpp @@ -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()); } } @@ -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()); } } diff --git a/test/testunusedfunctions.cpp b/test/testunusedfunctions.cpp index c919318585f9..f18f0953045b 100644 --- a/test/testunusedfunctions.cpp +++ b/test/testunusedfunctions.cpp @@ -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()); } };