[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [stegotorus/master] Add fallback logic for static_assert in compilers that don't support it.
commit 5ce688f4193828197130b4c91c7c32b53b5b5568
Author: Zack Weinberg <zackw@xxxxxxx>
Date: Wed Mar 28 09:01:09 2012 -0700
Add fallback logic for static_assert in compilers that don't support it.
---
configure.ac | 1 +
m4/cxx_delete_method.m4 | 8 ++++--
m4/cxx_static_assert.m4 | 57 ++++++++++++++++++++++++++++++++++++++++++++++
m4/cxxflags_stdcxx_11.m4 | 4 ---
4 files changed, 63 insertions(+), 7 deletions(-)
diff --git a/configure.ac b/configure.ac
index 9002078..69f4150 100644
--- a/configure.ac
+++ b/configure.ac
@@ -68,6 +68,7 @@ AC_CHECK_HEADERS([execinfo.h],,, [AC_INCLUDES_DEFAULT()])
AX_CXXFLAGS_STDCXX_11([ext])
AX_CXX_DELETE_METHOD
+AX_CXX_STATIC_ASSERT
### Output ###
diff --git a/m4/cxx_delete_method.m4 b/m4/cxx_delete_method.m4
index 2f7decf..2d467e7 100644
--- a/m4/cxx_delete_method.m4
+++ b/m4/cxx_delete_method.m4
@@ -50,7 +50,8 @@ AC_DEFUN([AX_CXX_DELETE_METHOD], [dnl
[ax_cv_cxx_delete_method_syntax=yes],
[ax_cv_cxx_delete_method_syntax=no])])
# ... and this one should fail.
- AC_CACHE_CHECK(whether $CXX enforces method deletion,
+ if test x$ax_cv_cxx_delete_method_syntax = xyes; then
+ AC_CACHE_CHECK(whether $CXX enforces method deletion,
ax_cv_cxx_delete_method_enforced, [
AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
struct foo {
@@ -62,8 +63,9 @@ AC_DEFUN([AX_CXX_DELETE_METHOD], [dnl
]])],
[ax_cv_cxx_delete_method_enforced=no],
[ax_cv_cxx_delete_method_enforced=yes])])
- if test $ax_cv_cxx_delete_method_syntax = yes &&
- test $ax_cv_cxx_delete_method_enforced = yes
+ fi
+ if test x$ax_cv_cxx_delete_method_syntax = xyes &&
+ test x$ax_cv_cxx_delete_method_enforced = xyes
then
AC_DEFINE([DELETE_METHOD], [= delete],
[Define as `= delete' if your compiler supports C++11 method
diff --git a/m4/cxx_static_assert.m4 b/m4/cxx_static_assert.m4
new file mode 100644
index 0000000..7bf69f8
--- /dev/null
+++ b/m4/cxx_static_assert.m4
@@ -0,0 +1,57 @@
+# SYNOPSIS
+#
+# AX_CXX_STATIC_ASSERT
+#
+# DESCRIPTION
+#
+# Detect whether the C++ compiler, in its present operating mode,
+# supports the C++11 'static_assert' construct. If it doesn't,
+# define 'static_assert' as a preprocessor macro which provides
+# more-or-less the same functionality.
+#
+# LICENSE
+#
+# Copyright (c) 2012 Zack Weinberg <zackw@xxxxxxxxx>
+#
+# Copying and distribution of this file, with or without modification, are
+# permitted in any medium without royalty provided the copyright notice
+# and this notice are preserved. This file is offered as-is, without any
+# warranty.
+
+#serial 1
+
+AC_DEFUN([AX_CXX_STATIC_ASSERT], [dnl
+ AC_LANG_ASSERT([C++])dnl
+ AC_CACHE_CHECK(whether $CXX accepts static_assert, ax_cv_cxx_static_assert,
+ [AC_COMPILE_IFELSE([AC_LANG_SOURCE([dnl
+ template <typename T>
+ struct check
+ { static_assert(sizeof(int) <= sizeof(T), "not big enough"); };
+ check<int> ok;])],
+ [ax_cv_cxx_static_assert=yes], [ax_cv_cxx_static_assert=no])])
+ if test x$ax_cv_cxx_static_assert = xyes; then
+ AC_CACHE_CHECK(whether $CXX enforces static_assert, ax_cv_cxx_static_assert_e,
+ [AC_COMPILE_IFELSE([AC_LANG_SOURCE([dnl
+ template <typename T>
+ struct check
+ { static_assert(sizeof(char[2]) <= sizeof(T), "not big enough"); };
+ check<char> bad;])],
+ [ax_cv_cxx_static_assert_e=no], [ax_cv_cxx_static_assert_e=yes])])
+ fi
+ if test x$ax_cv_cxx_static_assert = xyes &&
+ test x$ax_cv_cxx_static_assert_e = xyes; then
+ AC_DEFINE(HAVE_STATIC_ASSERT, 1,
+ [Define to 1 if the C++ compiler supports static_assert.])
+ fi
+ AH_VERBATIM([HAVE_STATIC_ASSERT_],
+[#ifndef HAVE_STATIC_ASSERT
+# define static_assert(expr, msg) typedef char static_assert_id[(expr)?1:-1]
+# ifdef __COUNTER__
+# define static_assert_id static_assert_paste(static_assert_, __COUNTER__)
+# else
+# define static_assert_id static_assert_paste(static_assert_, __LINE__)
+# endif
+# define static_assert_paste(a,b) static_assert_paste_(a,b)
+# define static_assert_paste_(a,b) a##b
+#endif])
+])
diff --git a/m4/cxxflags_stdcxx_11.m4 b/m4/cxxflags_stdcxx_11.m4
index 383b708..7f06ed2 100644
--- a/m4/cxxflags_stdcxx_11.m4
+++ b/m4/cxxflags_stdcxx_11.m4
@@ -99,8 +99,4 @@ AC_DEFUN([AX_CXXFLAGS_STDCXX_11], [dnl
fi
done
fi])
-
- if test x$ac_success = xno; then
- AC_MSG_WARN([*** Compiler support for C++11 language features not detected.])
- fi
])
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits