1
0
mirror of https://github.com/Kitware/CMake.git synced 2025-10-16 05:26:58 +08:00

Extend C++17 feature checks to require std::optional

This commit is contained in:
Brad King
2019-08-22 08:28:08 -04:00
parent 43fe736b2b
commit 170fcd715f
2 changed files with 19 additions and 2 deletions

View File

@@ -1,6 +1,7 @@
#include <cstdio>
#include <iterator>
#include <memory>
#include <optional>
#include <unordered_map>
#ifdef _MSC_VER
@@ -27,5 +28,7 @@ int main()
IDispatchPtr disp(ptr);
#endif
return *u + *ai + *(bi - 1) + (3 - static_cast<int>(ci));
std::optional<int> oi = 0;
return *u + *ai + *(bi - 1) + (3 - static_cast<int>(ci)) + oi.value();
}

View File

@@ -1146,6 +1146,20 @@ int check_cxx14()
}
#endif
#if __cplusplus >= 201703L
#include <optional>
int check_cxx17()
{
std::optional<int> oi = 0;
return oi.value();
}
#else
int check_cxx17()
{
return 0;
}
#endif
class Class
{
public:
@@ -1156,7 +1170,7 @@ private:
int main()
{
auto const c = std::unique_ptr<Class>(new Class);
std::cout << c->Get() << check_cxx14() << std::endl;
std::cout << c->Get() << check_cxx14() << check_cxx17() << std::endl;
return 0;
}
' > "${TMPFILE}.cxx"