From 597dd1f91d9f3823e4184f1fe73d8125fa16c026 Mon Sep 17 00:00:00 2001 From: Chuanqi Xu Date: Wed, 24 May 2023 11:41:26 +0800 Subject: [PATCH] [NFC] Fix the warning for dangling pointer for c0d6f85e3ae8bc The bot notes a warning-converted-error for the dangling pointer. And the patch fixes that. --- .../Serialization/VarDeclConstantInitTest.cpp | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/clang/unittests/Serialization/VarDeclConstantInitTest.cpp b/clang/unittests/Serialization/VarDeclConstantInitTest.cpp index 4445030..33fc82b 100644 --- a/clang/unittests/Serialization/VarDeclConstantInitTest.cpp +++ b/clang/unittests/Serialization/VarDeclConstantInitTest.cpp @@ -95,15 +95,10 @@ export namespace Fibonacci CreateInvocationOptions CIOpts; CIOpts.Diags = Diags; - llvm::Twine CacheBMIPath = TestDir + "/Cached.pcm"; - const char *Args[] = {"clang++", - "-std=c++20", - "--precompile", - "-working-directory", - TestDir.c_str(), - "Cached.cppm", - "-o", - CacheBMIPath.str().c_str()}; + std::string CacheBMIPath = llvm::Twine(TestDir + "/Cached.pcm").str(); + const char *Args[] = { + "clang++", "-std=c++20", "--precompile", "-working-directory", + TestDir.c_str(), "Cached.cppm", "-o", CacheBMIPath.c_str()}; std::shared_ptr Invocation = createInvocation(Args, CIOpts); ASSERT_TRUE(Invocation); @@ -115,12 +110,13 @@ export namespace Fibonacci ASSERT_TRUE(Instance.ExecuteAction(Action)); ASSERT_FALSE(Diags->hasErrorOccurred()); - llvm::Twine DepArg = "-fmodule-file=Fibonacci.Cache=" + CacheBMIPath; + std::string DepArg = + llvm::Twine("-fmodule-file=Fibonacci.Cache=" + CacheBMIPath).str(); std::unique_ptr AST = tooling::buildASTFromCodeWithArgs( R"cpp( import Fibonacci.Cache; )cpp", - /*Args=*/{"-std=c++20", DepArg.str().c_str()}); + /*Args=*/{"-std=c++20", DepArg.c_str()}); using namespace clang::ast_matchers; ASTContext &Ctx = AST->getASTContext(); -- 2.7.4