ax_cpp11.m4 4.01 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
AC_DEFUN([AX_ISC_CPP11], [

CXX_SAVED=$CXX
feature=
for retry in "none" "--std=c++11" "--std=c++0x" "--std=c++1x" "fail"; do
	if test "$retry" = "fail"; then
		AC_MSG_ERROR([$feature (a C++11 feature) is not supported])
	fi
	if test "$retry" != "none"; then
		AC_MSG_WARN([unsupported C++11 feature])
		AC_MSG_NOTICE([retrying by adding $retry to $CXX])
		CXX="$CXX_SAVED $retry"
		AC_MSG_CHECKING($retry support)
		AC_COMPILE_IFELSE(
			[AC_LANG_PROGRAM(
				[],
				[int myincr = 1;])],
			[AC_MSG_RESULT([yes])],
			[AC_MSG_RESULT([no])
			 continue])
	fi

	AC_MSG_CHECKING(std::unique_ptr support)
	feature="std::unique_ptr"
	AC_COMPILE_IFELSE(
		[AC_LANG_PROGRAM(
			[#include <memory>],
			[std::unique_ptr<int> a;])],
		[AC_MSG_RESULT([yes])],
		[AC_MSG_RESULT([no])
		 continue])

	AC_MSG_CHECKING(cbegin/cend support)
	feature="cbegin/cend"
	AC_COMPILE_IFELSE(
		[AC_LANG_PROGRAM(
			[#include <string>],
			[const std::string& s = "abcd";
			 unsigned count = 0;
			 for (std::string::const_iterator i = s.cbegin();
			      i != s.cend(); ++i)
				if (*i == 'b')
					++count;])],
		[AC_MSG_RESULT([yes])],
		[AC_MSG_RESULT([no])
		 continue])

	AC_MSG_CHECKING(final method support)
	feature="final method"
	AC_COMPILE_IFELSE(
		[AC_LANG_PROGRAM(
			[class Foo {
			 public:
			 	virtual ~Foo() {};
				virtual void bar() final;
			 };],[])],
		 [AC_MSG_RESULT([yes])],
		 [AC_MSG_RESULT([no])
		  continue])

61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
	AC_MSG_CHECKING(override method support)
	feature="override method"
	AC_COMPILE_IFELSE(
		[AC_LANG_PROGRAM(
			[class Foo {
			 public:
			 	virtual ~Foo() {};
				virtual void foobar();
			 };
			 class Bar : public Foo {
                         public:
			 	virtual ~Bar() {};
				virtual void foobar() override;
			 };],[])],
		 [AC_MSG_RESULT([yes])],
		 [AC_MSG_RESULT([no])
		  continue])

79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
	AC_MSG_CHECKING(aggregate initialization support)
	feature="aggregate initialization"
	AC_COMPILE_IFELSE(
		[AC_LANG_PROGRAM(
			[#include <vector>],
			[std::vector<int> foo = { 1, 2, 3};])],
		[AC_MSG_RESULT([yes])],
		[AC_MSG_RESULT([no])
		 continue])

	AC_MSG_CHECKING(variadic template support)
	feature="variadic template"
	AC_COMPILE_IFELSE(
		[AC_LANG_PROGRAM(
			[template<typename ... Args>
			 struct A {
			 void foo(Args... myargs) { return; };
			 };],
			 [A<> a;
			  a.foo();])],
		[AC_MSG_RESULT([yes])],
		[AC_MSG_RESULT([no])
		 continue])

	AC_MSG_CHECKING(static_assert support)
	feature="static_assert"
	AC_COMPILE_IFELSE(
		[AC_LANG_PROGRAM(
			[static_assert(1 + 1 == 2, "");],
			[])],
		[AC_MSG_RESULT([yes])],
		[AC_MSG_RESULT([no])
		 continue])

	AC_MSG_CHECKING(template alias)
	feature="template alias"
	AC_COMPILE_IFELSE(
		[AC_LANG_PROGRAM(
			[template<int i>
			 class I {
			 public: int get() { return i; };
			 };
			 using Zero = I<0>;],
			[Zero Z;
			 return Z.get();])],
		[AC_MSG_RESULT([yes])],
		[AC_MSG_RESULT([no])
		 continue])

128 129 130 131 132 133 134 135 136 137 138 139 140
	AC_MSG_CHECKING(constexpr support)
	feature="constexpr"
	AC_COMPILE_IFELSE(
		[AC_LANG_PROGRAM(
			[#include <string>
			 typedef char const* const Tag;
			 constexpr Tag FOOBAR = "FOOBAR";],
			[const std::string foobar(FOOBAR);
			 return static_cast<int>(foobar.length());])],
		[AC_MSG_RESULT([yes])],
		[AC_MSG_RESULT([no])
		 continue])

141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
	AC_MSG_CHECKING(enum class support)
	feature="enum class"
	AC_COMPILE_IFELSE(
		[AC_LANG_PROGRAM(
			[enum class FooBar {
			     FOO = 1,
			     BAR = 2
			 };],
			[FooBar f = FooBar::FOO;
			 return (f == FooBar::FOO ? 1 : 2);])],
		[AC_MSG_RESULT([yes])],
		[AC_MSG_RESULT([no])
		 continue])

	AC_MSG_CHECKING(range-for support)
	feature="constexpr"
	AC_COMPILE_IFELSE(
		[AC_LANG_PROGRAM(
			[#include <vector>
			 std::vector<int> v = { 1, 2, 3, 4 };],
			[int sum = 0;
			 for (auto i : v) {
			     sum += i;
			 }
			 return sum;])],
		[AC_MSG_RESULT([yes])],
		[AC_MSG_RESULT([no])
		 continue])

170 171 172 173 174 175 176 177 178 179 180 181 182
	AC_MSG_CHECKING(lambda support)
	feature="lambda"
	AC_COMPILE_IFELSE(
		[AC_LANG_PROGRAM(
			[],
			[auto myincr = [[]](int x) { return x + 1; };])],
		[AC_MSG_RESULT([yes])
		 break],
		[AC_MSG_RESULT([no])
		 continue])
done

])dnl AX_ISC_RPATH