diff --git a/CMakeLists.txt b/CMakeLists.txt index 26332d9..f38f1fe 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,7 +25,8 @@ message("== Report build errors to https://github.com/esseks/monicelli/issues") ## 1. Compiler sanity check -try_compile( +try_run( + execution_results supported_compiler ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/cmake/features.cpp @@ -44,6 +45,14 @@ if (NOT supported_compiler) ) endif() +if (execution_results MATCHES FAILED_TO_RUN) + message(FATAL_ERROR + "Your compiler supports the set of C++11 features we need, " + "but something failed.\n" + "Run cmake with -Dcheckfeat=1 to see the exact cause." + ) +endif() + ## 2. Find Flex and Bison find_package(BISON REQUIRED) diff --git a/cmake/features.cpp b/cmake/features.cpp index 051ba0e..b6187ca 100644 --- a/cmake/features.cpp +++ b/cmake/features.cpp @@ -28,6 +28,24 @@ #include #include +#include + + +const int global_i = 0; + +struct TestingReferenceBinding { + TestingReferenceBinding(int const& ii) { + assert(&ii == &global_i); + } + + void operator=(int const& ii) { + assert(&ii == &global_i); + } + + void operator=(int&&) { + assert(false); + } +}; enum class Dummy { FOO, BAR, BAZ @@ -37,6 +55,12 @@ class Banana { int yep() const noexcept { return 0; } + + virtual void something() {} +}; + +class Phone: public Banana { + virtual void something() override {} }; int main() { @@ -49,4 +73,14 @@ int main() { Banana a; Banana b = std::move(a); long c = std::stol("100"); + + // Boost::Optional sanity check for old compilers + int const& iref = global_i; + assert(&iref == &global_i); + + TestingReferenceBinding ttt = global_i; + ttt = global_i; + + TestingReferenceBinding ttt2 = iref; + ttt2 = iref; }