Browse Source

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 years ago
parent
commit
ba981bb2ed
1 changed files with 2 additions and 1 deletions
  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)