summaryrefslogtreecommitdiff
path: root/Source/Checks
diff options
context:
space:
mode:
authorMathieu Garaud <mathieu.garaud@gmail.com>2019-02-27 15:47:41 +0100
committerBrad King <brad.king@kitware.com>2019-02-27 11:24:43 -0500
commite17deb7ad4ac83207c9e34d397f3ee054b3d09dd (patch)
tree8d972947d211a01ea3e81d2c5237c25507a71be0 /Source/Checks
parente6897c72e7c59f7a0b82ed19c1bdb40d42f7adaa (diff)
downloadcmake-e17deb7ad4ac83207c9e34d397f3ee054b3d09dd.tar.gz
Extend C++17/C++14 feature checks to cover more standard library APIs
Make sure `std::cbegin`, `std::cend`, and `std::size` work in C++17 or C++14 mode before choosing the corresponding standard level for compiling CMake itself. This helps in cases that the compiler is using a standard library too old to support the full standard level chosen.
Diffstat (limited to 'Source/Checks')
-rw-r--r--Source/Checks/cm_cxx14_check.cpp9
-rw-r--r--Source/Checks/cm_cxx17_check.cpp11
2 files changed, 18 insertions, 2 deletions
diff --git a/Source/Checks/cm_cxx14_check.cpp b/Source/Checks/cm_cxx14_check.cpp
index 9369ba261a..fff36c9161 100644
--- a/Source/Checks/cm_cxx14_check.cpp
+++ b/Source/Checks/cm_cxx14_check.cpp
@@ -1,8 +1,15 @@
#include <cstdio>
+#include <iterator>
#include <memory>
int main()
{
+ int a[] = { 0, 1, 2 };
+ auto ai = std::cbegin(a);
+
+ int b[] = { 2, 1, 0 };
+ auto bi = std::cend(b);
+
std::unique_ptr<int> u(new int(0));
- return *u;
+ return *u + *ai + *(bi - 1);
}
diff --git a/Source/Checks/cm_cxx17_check.cpp b/Source/Checks/cm_cxx17_check.cpp
index 4e8918454a..9ea52c4569 100644
--- a/Source/Checks/cm_cxx17_check.cpp
+++ b/Source/Checks/cm_cxx17_check.cpp
@@ -1,9 +1,18 @@
#include <cstdio>
+#include <iterator>
#include <memory>
#include <unordered_map>
int main()
{
+ int a[] = { 0, 1, 2 };
+ auto ai = std::cbegin(a);
+
+ int b[] = { 2, 1, 0 };
+ auto bi = std::cend(b);
+
+ auto ci = std::size(a);
+
std::unique_ptr<int> u(new int(0));
- return *u;
+ return *u + *ai + *(bi - 1) + (3 - static_cast<int>(ci));
}