From ba981bb2ed170a6e59614657b04b204f7db4893d Mon Sep 17 00:00:00 2001 From: Craig Scott Date: Wed, 28 Dec 2022 17:06:21 +1100 Subject: TryCompileCode(): Prevent warning on return value Some newer compilers warn in situations where the returned local variable could be movable, but a C++11 defect meant older compilers may still return a copy when a type conversion is involved. Adding the suggested std::move prevents that warning on that compiler, but creates a new warning on others. Constructing the actual return type explicitly with the suggested std::move on the constructor argument keeps both sets of compilers happy. --- Source/cmCoreTryCompile.cxx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Source/cmCoreTryCompile.cxx b/Source/cmCoreTryCompile.cxx index 25a0e2d..2a4ea80 100644 --- a/Source/cmCoreTryCompile.cxx +++ b/Source/cmCoreTryCompile.cxx @@ -7,6 +7,7 @@ #include #include #include +#include #include #include @@ -1131,7 +1132,7 @@ cm::optional cmCoreTryCompile::TryCompileCode( result.VariableCached = !arguments.NoCache; result.Output = std::move(output); result.ExitCode = res; - return result; + return cm::optional(std::move(result)); } bool cmCoreTryCompile::IsTemporary(std::string const& path) -- cgit v0.12