浏览代码

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.
Craig Scott 3 年之前
父节点
当前提交
ba981bb2ed
共有 1 个文件被更改,包括 2 次插入1 次删除
  1. 2 1
      Source/cmCoreTryCompile.cxx

+ 2 - 1
Source/cmCoreTryCompile.cxx

@@ -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)