[clang] 597dd1f - [NFC] Fix the warning for dangling pointer for c0d6f85e3ae8bc

Chuanqi Xu via cfe-commits cfe-commits at lists.llvm.org
Tue May 23 20:44:21 PDT 2023


Author: Chuanqi Xu
Date: 2023-05-24T11:42:55+08:00
New Revision: 597dd1f91d9f3823e4184f1fe73d8125fa16c026

URL: https://github.com/llvm/llvm-project/commit/597dd1f91d9f3823e4184f1fe73d8125fa16c026
DIFF: https://github.com/llvm/llvm-project/commit/597dd1f91d9f3823e4184f1fe73d8125fa16c026.diff

LOG: [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.

Added: 
    

Modified: 
    clang/unittests/Serialization/VarDeclConstantInitTest.cpp

Removed: 
    


################################################################################
diff  --git a/clang/unittests/Serialization/VarDeclConstantInitTest.cpp b/clang/unittests/Serialization/VarDeclConstantInitTest.cpp
index 4445030122d5..33fc82b9adc7 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<CompilerInvocation> 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<ASTUnit> 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();


        


More information about the cfe-commits mailing list