The attached patch introduces three macros:
  AC_CXX_CONSTEXPR
  AC_CXX_FINAL
  AC_CXX_NULLPTR
which behave like AC_C_CONST et al but are for the new
C++11 constextr, final and nullptr keywords.  I can add
additional macros for other keywords, but not all of them
have the possibility of falling back e.g. decltype, so I
have excluded these for now since I don't see these as
being useful additions.

I would also like to add checks for a number of types which
have implementations in the std:: (C++11) and std::tr1 (C++98TR1)
and boost:: (Boost) namespaces.  Examples: regex, tuple, memory.
In many projects, I have logic in compatibility headers such as
follows.  In brief, these include the std:: header (if present)
or else include the std::tr1 header (if present) or else include
the boost:: header (if present) or else fail.  This permits once
to use the C++11 types with fallback to C++98TR1 or Boost being
completely transparent.

Would including macros such as AC_CXX_MEMORY, AC_CXX_TUPLE,
AC_CXX_REGEX etc. be acceptable?  If so, is it acceptable to
include logic similar to the following in config.h or an
alternate header?  Does autoconf allow the user to specify
which header will be used to e.g. redirect C++-specific
stuff to a specific header?


Regards,
Roger


# ifdef HAVE_MEMORY_SHARED_PTR
#  include <memory>
# elif HAVE_TR1_MEMORY
# include <tr1/memory>
namespace std {
    using std::tr1::shared_ptr;
    using std::tr1::weak_ptr;
    using std::tr1::static_pointer_cast;
    using std::tr1::const_pointer_cast;
    using std::tr1::dynamic_pointer_cast;
}
# elif HAVE_BOOST_SHARED_PTR_HPP
#  include <boost/shared_ptr.hpp>
namespace std {
    using boost::shared_ptr;
    using boost::weak_ptr;
    using boost::static_pointer_cast;
    using boost::const_pointer_cast;
    using boost::dynamic_pointer_cast;
}
# else
#  error A shared_ptr implementation is not available
# endif

# ifdef HAVE_TUPLE
#  include <tuple>
# elif HAVE_TR1_TUPLE
#  include <tr1/tuple>
namespace std {
  using tr1::tuple;
  using tr1::get;
}
# elif HAVE_BOOST_TUPLE_TUPLE_HPP
#  include <boost/tuple/tuple.hpp>
namespace std {
  using boost::tuple;
  using boost::get;
}
# else
#  error A tuple implementation is not available
# endif


-- 
  .''`.  Roger Leigh
 : :' :  Debian GNU/Linux    http://people.debian.org/~rleigh/
 `. `'   schroot and sbuild  http://alioth.debian.org/projects/buildd-tools
   `-    GPG Public Key      F33D 281D 470A B443 6756 147C 07B3 C8BC 4083 E800
>From afa1f8df49d1b95c2553604ae621ab7b10eb48aa Mon Sep 17 00:00:00 2001
From: Roger Leigh <rle...@debian.org>
Date: Sun, 3 Feb 2013 00:51:45 +0000
Subject: [PATCH] C++: Add AC_CXX_CONSTEXPR, AC_CXX_FINAL and AC_CXX_NULLPTR

---
 doc/autoconf.texi |   41 ++++++++++++++++++++++++++++++++++++
 lib/autoconf/c.m4 |   60 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 101 insertions(+)

diff --git a/doc/autoconf.texi b/doc/autoconf.texi
index 8f58d4a..d93820f 100644
--- a/doc/autoconf.texi
+++ b/doc/autoconf.texi
@@ -7704,6 +7704,47 @@ Test whether the C++ compiler accepts the options @option{-c} and
 if it does not.
 @end defmac
 
+@anchor{AC_CXX_CONSTEXPR}
+@defmac AC_CXX_CONSTEXPR
+@acindex{CXX_CONSTEXPR}
+@cvindex constexpr
+@caindex cxx_constexpr
+If the C++ compiler does not fully support the @code{constexpr} keyword,
+define @code{constexpr} to be empty.  Programs can simply use
+@code{constexpr} as if every C++ compiler supported it; for those that
+don't, the makefile or configuration header file defines it as empty.
+Note that code which requires @code{constexpr}, e.g. for sizing an
+array based upon a constant expression evaluation, will not work with
+this fallback.
+
+This macro caches its result in the @code{ac_cv_cxx_constexpr} variable.
+@end defmac
+
+@anchor{AC_CXX_FINAL}
+@defmac AC_CXX_FINAL
+@acindex{CXX_FINAL}
+@cvindex final
+@caindex cxx_final
+If the C++ compiler does not fully support the @code{final} keyword,
+define @code{final} to be empty.  Programs can simply use
+@code{final} as if every C++ compiler supported it; for those that
+don't, the makefile or configuration header file defines it as empty.
+
+This macro caches its result in the @code{ac_cv_cxx_final} variable.
+@end defmac
+
+@anchor{AC_CXX_NULLPTR}
+@defmac AC_CXX_NULLPTR
+@acindex{CXX_NULLPTR}
+@cvindex nullptr
+@caindex cxx_nullptr
+If the C++ compiler does not fully support the @code{nullptr} keyword,
+define @code{nullptr} to be empty.  Programs can simply use
+@code{nullptr} as if every C++ compiler supported it; for those that
+don't, the makefile or configuration header file defines it as @code{0}.
+
+This macro caches its result in the @code{ac_cv_cxx_nullptr} variable.
+@end defmac
 
 @node Objective C Compiler
 @subsection Objective C Compiler Characteristics
diff --git a/lib/autoconf/c.m4 b/lib/autoconf/c.m4
index 6fe00fb..a263613 100644
--- a/lib/autoconf/c.m4
+++ b/lib/autoconf/c.m4
@@ -2494,3 +2494,63 @@ dnl Tru64	N/A (no support)
 dnl with extended modes being tried first.
 [[-std=gnu++11 -std=c++11 -std=gnu++0x -std=c++0x -qlanglvl=extended0x -AA]], [$1], [$2])[]dnl
 ])# _AC_PROG_CXX_CXX11
+
+# AC_CXX_CONSTEXPR
+# ----------------
+AC_DEFUN([AC_CXX_CONSTEXPR],
+[AC_CACHE_CHECK([for working constexpr], ac_cv_cxx_constexpr,
+[AC_LANG_PUSH(C++)dnl
+AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
+constexpr int get_val() { return 20; }
+]], [[
+  short sa[get_val()] = { 0 };
+]])],
+		   [ac_cv_cxx_constexpr=yes],
+		   [ac_cv_cxx_constexpr=no])])
+AC_LANG_POP(C++)dnl
+if test $ac_cv_cxx_constexpr = no; then
+  AC_DEFINE(constexpr,,
+	    [Define to empty if the keyword `constexpr' does not work.
+	     Warning: valid code using `constexpr' can become incorrect
+	     without.  Disable with care.])
+fi
+])# AC_CXX_CONSTEXPR
+
+# AC_CXX_NULLPTR
+# --------------
+AC_DEFUN([AC_CXX_NULLPTR],
+[AC_CACHE_CHECK([for working nullptr], ac_cv_cxx_nullptr,
+[AC_LANG_PUSH(C++)dnl
+AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
+  char *c = nullptr;
+]])],
+		   [ac_cv_cxx_nullptr=yes],
+		   [ac_cv_cxx_nullptr=no])])
+AC_LANG_POP(C++)dnl
+if test $ac_cv_cxx_nullptr = no; then
+  AC_DEFINE(nullptr,0,
+	    [Define to 0 if the keyword `nullptr' does not work.])
+fi
+])# AC_CXX_NULLPTR
+
+# AC_CXX_FINAL
+# --------------
+AC_DEFUN([AC_CXX_FINAL],
+[AC_CACHE_CHECK([for working final], ac_cv_cxx_final,
+[AC_LANG_PUSH(C++)dnl
+AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
+class f1 final { int i; };
+
+class f2 { virtual void f() final {} };
+]], [[
+  f1 fi1;
+  f2 fi2;
+]])],
+		   [ac_cv_cxx_final=yes],
+		   [ac_cv_cxx_final=no])])
+AC_LANG_POP(C++)dnl
+if test $ac_cv_cxx_final = no; then
+  AC_DEFINE(final,,
+	    [Define to empty if the keyword `final' does not work.])
+fi
+])# AC_CXX_FINAL
-- 
1.7.10.4

_______________________________________________
Autoconf mailing list
Autoconf@gnu.org
https://lists.gnu.org/mailman/listinfo/autoconf

Reply via email to