aboutsummaryrefslogtreecommitdiff
path: root/clang
diff options
context:
space:
mode:
authorYoungsuk Kim <youngsuk.kim@hpe.com>2024-06-30 10:02:47 -0500
committerYoungsuk Kim <youngsuk.kim@hpe.com>2024-06-30 10:02:49 -0500
commitac84ada9a169a72ad136ef05c2c194f594f24a37 (patch)
treecb91f6bd179da3c65ac31df81e0359b70e96330b /clang
parent2051736f7bc3fb1a8daaeecc854f93604a590aba (diff)
downloadllvm-ac84ada9a169a72ad136ef05c2c194f594f24a37.zip
llvm-ac84ada9a169a72ad136ef05c2c194f594f24a37.tar.gz
llvm-ac84ada9a169a72ad136ef05c2c194f594f24a37.tar.bz2
[clang] Avoid 'raw_string_ostream::str' (NFC)
Since `raw_string_ostream` doesn't own the string buffer, it is desirable (in terms of memory safety) for users to directly reference the string buffer rather than use `raw_string_ostream::str()`. Work towards TODO comment to remove `raw_string_ostream::str()`.
Diffstat (limited to 'clang')
-rw-r--r--clang/lib/Tooling/Transformer/Stencil.cpp4
-rw-r--r--clang/unittests/AST/MatchVerifier.h16
-rw-r--r--clang/unittests/Interpreter/InterpreterTest.cpp4
-rw-r--r--clang/unittests/Tooling/RecursiveASTVisitorTests/DeductionGuide.cpp2
-rw-r--r--clang/unittests/Tooling/ReplacementsYamlTest.cpp4
5 files changed, 15 insertions, 15 deletions
diff --git a/clang/lib/Tooling/Transformer/Stencil.cpp b/clang/lib/Tooling/Transformer/Stencil.cpp
index d91c9e0..bc4fa6e 100644
--- a/clang/lib/Tooling/Transformer/Stencil.cpp
+++ b/clang/lib/Tooling/Transformer/Stencil.cpp
@@ -51,7 +51,7 @@ static Error printNode(StringRef Id, const MatchFinder::MatchResult &Match,
if (auto Err = NodeOrErr.takeError())
return Err;
NodeOrErr->print(Os, PrintingPolicy(Match.Context->getLangOpts()));
- *Result += Os.str();
+ *Result += Output;
return Error::success();
}
@@ -371,7 +371,7 @@ public:
Stream << ", " << DefaultStencil->toString();
}
Stream << ")";
- return Stream.str();
+ return Buffer;
}
private:
diff --git a/clang/unittests/AST/MatchVerifier.h b/clang/unittests/AST/MatchVerifier.h
index da1e351d..60bb4a8 100644
--- a/clang/unittests/AST/MatchVerifier.h
+++ b/clang/unittests/AST/MatchVerifier.h
@@ -209,7 +209,7 @@ protected:
<< ">, found <";
Loc.print(Msg, *Result.SourceManager);
Msg << '>';
- this->setFailure(Msg.str());
+ this->setFailure(MsgStr);
}
}
@@ -256,7 +256,7 @@ protected:
Msg << '-';
End.print(Msg, *Result.SourceManager);
Msg << '>';
- this->setFailure(Msg.str());
+ this->setFailure(MsgStr);
}
}
@@ -282,12 +282,12 @@ protected:
llvm::raw_string_ostream Dump(DumpStr);
Node.dump(Dump, *Result.Context);
- if (Dump.str().find(ExpectSubstring) == std::string::npos) {
+ if (DumpStr.find(ExpectSubstring) == std::string::npos) {
std::string MsgStr;
llvm::raw_string_ostream Msg(MsgStr);
Msg << "Expected dump substring <" << ExpectSubstring << ">, found <"
- << Dump.str() << '>';
- this->setFailure(Msg.str());
+ << DumpStr << '>';
+ this->setFailure(MsgStr);
}
}
@@ -309,12 +309,12 @@ protected:
llvm::raw_string_ostream Print(PrintStr);
Node.print(Print, Result.Context->getPrintingPolicy());
- if (Print.str() != ExpectString) {
+ if (PrintStr != ExpectString) {
std::string MsgStr;
llvm::raw_string_ostream Msg(MsgStr);
Msg << "Expected pretty print <" << ExpectString << ">, found <"
- << Print.str() << '>';
- this->setFailure(Msg.str());
+ << PrintStr << '>';
+ this->setFailure(MsgStr);
}
}
diff --git a/clang/unittests/Interpreter/InterpreterTest.cpp b/clang/unittests/Interpreter/InterpreterTest.cpp
index bbd8541..29c5ead 100644
--- a/clang/unittests/Interpreter/InterpreterTest.cpp
+++ b/clang/unittests/Interpreter/InterpreterTest.cpp
@@ -101,7 +101,7 @@ TEST_F(InterpreterTest, Errors) {
auto Interp = createInterpreter(ExtraArgs, DiagPrinter.get());
auto Err = Interp->Parse("intentional_error v1 = 42; ").takeError();
using ::testing::HasSubstr;
- EXPECT_THAT(DiagnosticsOS.str(),
+ EXPECT_THAT(DiagnosticOutput,
HasSubstr("error: unknown type name 'intentional_error'"));
EXPECT_EQ("Parsing failed.", llvm::toString(std::move(Err)));
@@ -186,7 +186,7 @@ static std::string MangleName(NamedDecl *ND) {
std::string mangledName;
llvm::raw_string_ostream RawStr(mangledName);
MangleC->mangleName(ND, RawStr);
- return RawStr.str();
+ return mangledName;
}
TEST_F(InterpreterTest, FindMangledNameSymbol) {
diff --git a/clang/unittests/Tooling/RecursiveASTVisitorTests/DeductionGuide.cpp b/clang/unittests/Tooling/RecursiveASTVisitorTests/DeductionGuide.cpp
index 274f275..cd4bf0e 100644
--- a/clang/unittests/Tooling/RecursiveASTVisitorTests/DeductionGuide.cpp
+++ b/clang/unittests/Tooling/RecursiveASTVisitorTests/DeductionGuide.cpp
@@ -22,7 +22,7 @@ public:
std::string Storage;
llvm::raw_string_ostream Stream(Storage);
D->print(Stream);
- Match(Stream.str(), D->getLocation());
+ Match(Storage, D->getLocation());
return true;
}
diff --git a/clang/unittests/Tooling/ReplacementsYamlTest.cpp b/clang/unittests/Tooling/ReplacementsYamlTest.cpp
index 3328d9ba..9558d72 100644
--- a/clang/unittests/Tooling/ReplacementsYamlTest.cpp
+++ b/clang/unittests/Tooling/ReplacementsYamlTest.cpp
@@ -43,7 +43,7 @@ TEST(ReplacementsYamlTest, serializesReplacements) {
" Length: 2\n"
" ReplacementText: 'replacement #2'\n"
"...\n",
- YamlContentStream.str().c_str());
+ YamlContent.c_str());
}
TEST(ReplacementsYamlTest, serializesNewLines) {
@@ -67,7 +67,7 @@ TEST(ReplacementsYamlTest, serializesNewLines) {
" Length: 0\n"
" ReplacementText: \"#include <utility>\\n\"\n"
"...\n",
- YamlContentStream.str().c_str());
+ YamlContent.c_str());
}
TEST(ReplacementsYamlTest, deserializesReplacements) {