From 972cfd1bc393c56d249f1a2fbb8602e5d0c5bb07 Mon Sep 17 00:00:00 2001 From: Orkun Tokdemir Date: Tue, 4 Jul 2023 12:12:42 +0200 Subject: cmCustomCommandGenerator: Fix GetInternalDepfile on moved instance Previously the constructor captured `this` in a lambda used by the `GetInternalDepfile` method, but the pointer is invalidated when the instance moves. --- Source/cmCustomCommandGenerator.cxx | 13 +++++-------- Source/cmCustomCommandGenerator.h | 3 ++- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/Source/cmCustomCommandGenerator.cxx b/Source/cmCustomCommandGenerator.cxx index 2c1480a..634b63b 100644 --- a/Source/cmCustomCommandGenerator.cxx +++ b/Source/cmCustomCommandGenerator.cxx @@ -174,12 +174,6 @@ cmCustomCommandGenerator::cmCustomCommandGenerator( , EmulatorsWithArguments(cc.GetCommandLines().size()) , ComputeInternalDepfile(std::move(computeInternalDepfile)) { - if (!this->ComputeInternalDepfile) { - this->ComputeInternalDepfile = - [this](const std::string& cfg, const std::string& file) -> std::string { - return this->GetInternalDepfileName(cfg, file); - }; - } cmGeneratorExpression ge(*lg->GetCMakeInstance(), cc.GetBacktrace()); cmGeneratorTarget const* target{ lg->FindGeneratorTargetToUse( @@ -445,7 +439,7 @@ std::string cmCustomCommandGenerator::GetFullDepfile() const } std::string cmCustomCommandGenerator::GetInternalDepfileName( - const std::string& /*config*/, const std::string& depfile) + const std::string& /*config*/, const std::string& depfile) const { cmCryptoHash hash(cmCryptoHash::AlgoSHA256); std::string extension; @@ -469,7 +463,10 @@ std::string cmCustomCommandGenerator::GetInternalDepfile() const return ""; } - return this->ComputeInternalDepfile(this->OutputConfig, depfile); + if (this->ComputeInternalDepfile) { + return this->ComputeInternalDepfile(this->OutputConfig, depfile); + } + return this->GetInternalDepfileName(this->OutputConfig, depfile); } cm::optional cmCustomCommandGenerator::GetComment() const diff --git a/Source/cmCustomCommandGenerator.h b/Source/cmCustomCommandGenerator.h index 4453654..43bdd10 100644 --- a/Source/cmCustomCommandGenerator.h +++ b/Source/cmCustomCommandGenerator.h @@ -20,7 +20,8 @@ class cmLocalGenerator; class cmCustomCommandGenerator { - std::string GetInternalDepfileName(const std::string&, const std::string&); + std::string GetInternalDepfileName(const std::string&, + const std::string&) const; cmCustomCommand const* CC; std::string OutputConfig; -- cgit v0.12