From 878649c823766ca16235f4b23e5de80e9b8f3d10 Mon Sep 17 00:00:00 2001 From: Maximilien Colange Date: Tue, 13 Dec 2016 17:40:55 +0100 Subject: [PATCH] [buddy] Add an option to enable C++14. * configure.ac: add an option --enable-c++14. --- buddy/configure.ac | 79 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 70 insertions(+), 9 deletions(-) diff --git a/buddy/configure.ac b/buddy/configure.ac index af7d1195d..a7217f638 100644 --- a/buddy/configure.ac +++ b/buddy/configure.ac @@ -18,6 +18,12 @@ AC_PROG_YACC AC_PROG_CXX +# Option to activate C/C++14 +AC_ARG_ENABLE([c++14], + [AC_HELP_STRING([--enable-c++14], + [Use C++14.])], + [enable_14=yes], [enable_14=no]) + LT_INIT([win32-dll]) AX_BSYMBOLIC @@ -49,8 +55,10 @@ AC_LANG(C++) m4_define([_AX_CXX_COMPILE_STDCXX_11_testbody], [AC_LANG_SOURCE([#include #include +#include // fails with some installation of clang +#include - template + template struct check { static_assert(sizeof(int) <= sizeof(T), "not big enough"); @@ -68,16 +76,69 @@ m4_define([_AX_CXX_COMPILE_STDCXX_11_testbody], check_type&& cr = static_cast(c); auto d = a; + + void test_emplace() + { + std::map m; + m.emplace(1, 2); // fails with g++ 4.6 + } ])]) -for f in -std=c++11 '-std=c++11 -stdlib=libc++' -std=c++0x -do - AX_CHECK_COMPILE_FLAG([$f], [CXXFLAGS="$CXXFLAGS $f" stdpass=true], [], [], - [_AX_CXX_COMPILE_STDCXX_11_testbody]) - ${stdpass-false} && break -done -if ! "${stdpass-false}"; then - AC_ERROR([unable to turn on C++11 mode with this compiler]) +# Turn on C++14 support +# This is currently a copy of the above code for C++11, feel free to add +# further tests here when necessary. +m4_define([_AX_CXX_COMPILE_STDCXX_14_testbody], +[AC_LANG_SOURCE([#include +#include +#include // fails with some installation of clang +#include + + template + struct check + { + static_assert(sizeof(int) <= sizeof(T), "not big enough"); + }; + + typedef check> right_angle_brackets; + + auto f = std::make_shared("shared_ptr"); + + int a; + decltype(a) b; + + typedef check check_type; + check_type c; + check_type&& cr = static_cast(c); + + auto d = a; + + void test_emplace() + { + std::map m; + m.emplace(1, 2); // fails with g++ 4.6 + } +])]) + +if test x"${enable_14}" = xyes; then + for f in -std=c++14 '-std=c++14 -stdlib=libc++' -std=c++1y + do + AX_CHECK_COMPILE_FLAG([$f], [CXXFLAGS="$CXXFLAGS $f" stdpass=true], [], [], + [_AX_CXX_COMPILE_STDCXX_14_testbody]) + ${stdpass-false} && break + done + if ! "${stdpass-false}"; then + AC_ERROR([unable to turn on C++14 mode with this compiler]) + fi +else + for f in -std=c++11 '-std=c++11 -stdlib=libc++' -std=c++0x + do + AX_CHECK_COMPILE_FLAG([$f], [CXXFLAGS="$CXXFLAGS $f" stdpass=true], [], [], + [_AX_CXX_COMPILE_STDCXX_11_testbody]) + ${stdpass-false} && break + done + if ! "${stdpass-false}"; then + AC_ERROR([unable to turn on C++11 mode with this compiler]) + fi fi AC_CONFIG_HEADERS([config.h])