ax_cxx_def_template_arg.m4 1.6 KB

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