diff --git a/ChangeLog b/ChangeLog index 7a2730496..db2a7ce03 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2011-12-16 Alexandre Duret-Lutz + + Don't rely on the g++ version to include tr1/unordered_map and co. + + The previous setup failed with clang++ 3.0. + + * m4/stl.m4: New file. + * configure.ac: Call AC_HEADER_UNORDERED_MAP, + AC_HEADER_TR1_UNORDERED_MAP, and AC_HEADER_EXT_HASH_MAP. + * src/misc/hash.hh: Include _config.h, and used the + SPOT_HAVE_UNORDERED_MAP, SPOT_HAVE_TR1_UNORDERED_MAP, + or SPOT_HAVE_EXT_HASH_MAP defines to decide which + file to include. + 2011-12-01 Alexandre Duret-Lutz Fix mkdir error in ajax/spot.in. @@ -4331,7 +4345,7 @@ Update to compile with the Intel compiler. - * m4/intel.m4: New file. + * m4/intel.m4: New file. * configure.ac: Update. * src/tgbaalgos/emptiness.cc (tgba_run): Modify s.s->clone() in i->s->clone(). diff --git a/configure.ac b/configure.ac index 5cdefd619..746a2399a 100644 --- a/configure.ac +++ b/configure.ac @@ -46,6 +46,10 @@ AC_PROG_YACC AC_LANG(C++) +AC_HEADER_UNORDERED_MAP +AC_HEADER_TR1_UNORDERED_MAP +AC_HEADER_EXT_HASH_MAP + AX_CHECK_BUDDY AX_CHECK_LBTT AX_CHECK_GSPNLIB diff --git a/m4/stl.m4 b/m4/stl.m4 new file mode 100644 index 000000000..439630edd --- /dev/null +++ b/m4/stl.m4 @@ -0,0 +1,51 @@ + +AC_DEFUN([AC_HEADER_EXT_HASH_MAP], [ + AC_CACHE_CHECK([for ext/hash_map], + [ac_cv_cxx_ext_hash_map], + [AC_LANG_SAVE + AC_LANG_CPLUSPLUS + ac_save_CXXFLAGS="$CXXFLAGS" + CXXFLAGS="$CXXFLAGS -Werror" + AC_TRY_COMPILE([#include ], [using __gnu_cxx::hash_map;], + [ac_cv_cxx_ext_hash_map=yes], [ac_cv_cxx_ext_hash_map=no]) + CXXFLAGS="$ac_save_CXXFLAGS" + AC_LANG_RESTORE + ]) + if test "$ac_cv_cxx_ext_hash_map" = yes; then + AC_DEFINE([HAVE_EXT_HASH_MAP],, [Define if ext/hash_map is present.]) + fi +]) + +AC_DEFUN([AC_HEADER_TR1_UNORDERED_MAP], [ + AC_CACHE_CHECK([for tr1/unordered_map], + [ac_cv_cxx_tr1_unordered_map], + [AC_LANG_SAVE + AC_LANG_CPLUSPLUS + ac_save_CXXFLAGS="$CXXFLAGS" + CXXFLAGS="$CXXFLAGS -Werror" + AC_TRY_COMPILE([#include ], [using std::tr1::unordered_map;], + [ac_cv_cxx_tr1_unordered_map=yes], [ac_cv_cxx_tr1_unordered_map=no]) + CXXFLAGS="$ac_save_CXXFLAGS" + AC_LANG_RESTORE + ]) + if test "$ac_cv_cxx_tr1_unordered_map" = yes; then + AC_DEFINE([HAVE_TR1_UNORDERED_MAP],, [Define if tr1/unordered_map is present.]) + fi +]) + +AC_DEFUN([AC_HEADER_UNORDERED_MAP], [ + AC_CACHE_CHECK([for unordered_map], + [ac_cv_cxx_unordered_map], + [AC_LANG_SAVE + AC_LANG_CPLUSPLUS + ac_save_CXXFLAGS="$CXXFLAGS" + CXXFLAGS="$CXXFLAGS -Werror" + AC_TRY_COMPILE([#include ], [using std::unordered_map;], + [ac_cv_cxx_unordered_map=yes], [ac_cv_cxx_unordered_map=no]) + CXXFLAGS="$ac_save_CXXFLAGS" + AC_LANG_RESTORE + ]) + if test "$ac_cv_cxx_unordered_map" = yes; then + AC_DEFINE([HAVE_UNORDERED_MAP],, [Define if unordered_map is present.]) + fi +]) diff --git a/src/misc/hash.hh b/src/misc/hash.hh index f13a4fc72..9d2dde9be 100644 --- a/src/misc/hash.hh +++ b/src/misc/hash.hh @@ -26,11 +26,35 @@ # include # include -# include "hashfunc.hh" +# include "misc/hashfunc.hh" +# include "misc/_config.h" -// See the G++ FAQ for details about the following. -# ifdef __GNUC__ -# if __GNUC__ < 3 +#ifdef SPOT_HAVE_UNORDERED_MAP +# include +# include + namespace Sgi = std; +# define hash_map unordered_map +# define hash_multimap unordered_multimap +# define hash_set unordered_set +#else +#ifdef SPOT_HAVE_TR1_UNORDERED_MAP +# include +# include + namespace Sgi = std::tr1; +# define hash_map unordered_map +# define hash_multimap unordered_multimap +# define hash_set unordered_set +#else +#ifdef SPOT_HAVE_EXT_HASH_MAP +# include +# include +# if __GNUC__ == 3 && __GNUC_MINOR__ == 0 + namespace Sgi = std; // GCC 3.0 +# else + namespace Sgi = ::__gnu_cxx; // GCC 3.1 to 4.2 +# endif +#else +# if defined(__GNUC__) && (__GNUC__ < 3) # include # include namespace Sgi @@ -41,28 +65,13 @@ using ::hash; } # else -# if (__GNUC__ == 4 && __GNUC_MINOR__ >= 3) || __GNUC__ > 4 -# include // GCC 4.3 -# include - namespace Sgi = std::tr1; -# define hash_map unordered_map -# define hash_multimap unordered_multimap -# define hash_set unordered_set -# else -# include -# include -# if __GNUC__ == 3 && __GNUC_MINOR__ == 0 - namespace Sgi = std; // GCC 3.0 -# else - namespace Sgi = ::__gnu_cxx; // GCC 3.1 to 4.2 -# endif -# endif -# endif -# else // ... there are other compilers, right? # include # include namespace Sgi = std; # endif +#endif +#endif +#endif namespace spot { @@ -83,9 +92,9 @@ namespace spot /// \brief A hash function for strings. /// \ingroup hash_funcs /// @{ -# if (__GNUC__ == 4 && __GNUC_MINOR__ >= 3) || __GNUC__ > 4 - typedef std::tr1::hash string_hash; -# else // GCC < 4.3 +#if defined(SPOT_HAVE_UNORDERED_MAP) || defined(SPOT_HAVE_TR1_UNORDERED_MAP) + typedef Sgi::hash string_hash; +#else // e.g. GCC < 4.3 struct string_hash: public Sgi::hash, public std::unary_function @@ -98,7 +107,7 @@ namespace spot } }; /// @} -# endif +#endif /// \brief A hash function that returns identity /// \ingroup hash_funcs