ax_cxx_def_template_arg.m4 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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_LANG_WERROR([on])
  18. ac_success=no
  19. AC_CACHE_CHECK(whether $CXX supports default template arguments by default,
  20. ax_cv_cxx_compile_template,
  21. [AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_DEF_TEMPLATE_ARG_testbody])],
  22. [ax_cv_cxx_compile_template=yes],
  23. [ax_cv_cxx_compile_template=no])])
  24. if test x$ax_cv_cxx_compile_template = xyes; then
  25. ac_success=yes
  26. fi
  27. if test x$ac_success = xno; then
  28. for switch in -std=gnu++11 -std=gnu++0x -std=c++11 -std=c++0x; do
  29. cachevar=AS_TR_SH([ax_cv_cxx_compile_template_$switch])
  30. AC_CACHE_CHECK(whether $CXX default template arguments with $switch,
  31. $cachevar,
  32. [ac_save_CXXFLAGS="$CXXFLAGS"
  33. CXXFLAGS="$CXXFLAGS $switch"
  34. AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_DEF_TEMPLATE_ARG_testbody])],
  35. [eval $cachevar=yes],
  36. [eval $cachevar=no])
  37. CXXFLAGS="$ac_save_CXXFLAGS"])
  38. if eval test x\$$cachevar = xyes; then
  39. CXXFLAGS="$CXXFLAGS $switch"
  40. ac_success=yes
  41. break
  42. fi
  43. done
  44. fi
  45. AC_LANG_WERROR([on])
  46. AC_LANG_POP([C++])
  47. if test x$ac_success = xno; then
  48. AC_MSG_ERROR([*** Compiler does not support default template arguments in function templates.
  49. Please use a different compiler or specify the necessary CXXFLAGS.])
  50. fi
  51. ])