summaryrefslogtreecommitdiffstats
path: root/Source/cmCoreTryCompile.cxx
diff options
context:
space:
mode:
authorCraig Scott <craig.scott@crascit.com>2022-12-28 06:06:21 (GMT)
committerCraig Scott <craig.scott@crascit.com>2022-12-29 23:42:55 (GMT)
commitba981bb2ed170a6e59614657b04b204f7db4893d (patch)
tree45b825c7082262e495f25727e4d32d1ce558e3b4 /Source/cmCoreTryCompile.cxx
parenta1b71112d10b371610ef03b908ce9f2ab8eaeaf9 (diff)
downloadCMake-ba981bb2ed170a6e59614657b04b204f7db4893d.zip
CMake-ba981bb2ed170a6e59614657b04b204f7db4893d.tar.gz
CMake-ba981bb2ed170a6e59614657b04b204f7db4893d.tar.bz2
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.
Diffstat (limited to 'Source/cmCoreTryCompile.cxx')
-rw-r--r--Source/cmCoreTryCompile.cxx3
1 files changed, 2 insertions, 1 deletions
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 <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)