ax_cxx_def_template_arg.m4 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. # SYNOPSIS
  2. #
  3. # AX_CXX_DEF_TEMPLATE_ARG
  4. #
  5. # DESCRIPTION
  6. #
  7. # Check if the compiler supports default template arguments for function
  8. # templates and add necessary flags to CXXFLAGS.
  9. #
  10. m4_define([_AX_CXX_DEF_TEMPLATE_ARG_testbody], [[
  11. template <int T=0>
  12. int test(){ return T;};
  13. int test_default(){return test();};
  14. ]])
  15. AC_DEFUN([AX_CXX_DEF_TEMPLATE_ARG], [dnl
  16. AC_LANG_PUSH([C++])dnl
  17. ac_success=no
  18. AC_CACHE_CHECK(whether $CXX supports default template arguments by default,
  19. ax_cv_cxx_compile_template,
  20. [AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_DEF_TEMPLATE_ARG_testbody])],
  21. [ax_cv_cxx_compile_template=yes],
  22. [ax_cv_cxx_compile_template=no])])
  23. if test x$ax_cv_cxx_compile_template = xyes; then
  24. ac_success=yes
  25. fi
  26. if test x$ac_success = xno; then
  27. for switch in -std=gnu++11 -std=gnu++0x -std=c++11 -std=c++0x; do
  28. cachevar=AS_TR_SH([ax_cv_cxx_compile_template_$switch])
  29. AC_CACHE_CHECK(whether $CXX default template arguments with $switch,
  30. $cachevar,
  31. [ac_save_CXXFLAGS="$CXXFLAGS"
  32. CXXFLAGS="$CXXFLAGS $switch"
  33. AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_DEF_TEMPLATE_ARG_testbody])],
  34. [eval $cachevar=yes],
  35. [eval $cachevar=no])
  36. CXXFLAGS="$ac_save_CXXFLAGS"])
  37. if eval test x\$$cachevar = xyes; then
  38. CXXFLAGS="$CXXFLAGS $switch"
  39. ac_success=yes
  40. break
  41. fi
  42. done
  43. fi
  44. AC_LANG_POP([C++])
  45. if test x$ac_success = xno; then
  46. AC_MSG_ERROR([*** Compiler does not support default template arguments in function templates.
  47. Please use a different compiler or specify the necessary CXXFLAGS.])
  48. fi
  49. ])