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.
This commit is contained in:
Craig Scott
2022-12-28 17:06:21 +11:00
parent a1b71112d1
commit ba981bb2ed

View File

@@ -7,6 +7,7 @@
#include <cstring>
#include <set>
#include <sstream>
#include <type_traits>
#include <utility>
#include <cm/string_view>
@@ -1131,7 +1132,7 @@ cm::optional<cmTryCompileResult> cmCoreTryCompile::TryCompileCode(
result.VariableCached = !arguments.NoCache;
result.Output = std::move(output);
result.ExitCode = res;
return result;
return cm::optional<cmTryCompileResult>(std::move(result));
}
bool cmCoreTryCompile::IsTemporary(std::string const& path)