Ubuntu 12.10: error: range-based 'for'...

2013-02-15
2014-06-22
  • Christoph Korn
    Christoph Korn
    2013-02-15

    Trying to build mount-gtk-1.4.0 on Ubuntu 12.10 there is this error message in configure:
    checking for C++11 range-for support… configure: error: compiler does not support C++11 range-for expressions - if gcc is installed, gcc >= 4.6 required

    The gcc version is 4.7.2 actually so this cannot be the problem.

    The error message in config.log is:
    configure:7488: g++ -c -g -O2 -fstack-protector -param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 conftest.cpp >&5
    conftest.cpp: In function 'int main()':
    conftest.cpp:36:18: error: ISO C++ forbids declaration of 'elt' with no type
    conftest.cpp:36:23: error: range-based 'for' loops are not allowed in C++98 mode
    configure:7488: $? = 1
    configure: failed program was:
    | /* confdefs.h */
    | #define PACKAGE_NAME "mount-gtk"
    | #define PACKAGE_TARNAME "mount-gtk"
    | #define PACKAGE_VERSION "1.4.0"
    | #define PACKAGE_STRING "mount-gtk 1.4.0"
    | #define PACKAGE_BUGREPORT ""
    | #define PACKAGE_URL ""
    | #define PACKAGE "mount-gtk"
    | #define VERSION "1.4.0"
    | #define HAVE_CXX_GTK_UTILS_2 1
    | #define HAVE_LIBNOTIFY 1
    | #define STDC_HEADERS 1
    | #define HAVE_SYS_TYPES_H 1
    | #define HAVE_SYS_STAT_H 1
    | #define HAVE_STDLIB_H 1
    | #define HAVE_STRING_H 1
    | #define HAVE_MEMORY_H 1
    | #define HAVE_STRINGS_H 1
    | #define HAVE_INTTYPES_H 1
    | #define HAVE_STDINT_H 1
    | #define HAVE_UNISTD_H 1
    | #define HAVE_X11_XLIB_H 1
    | #define HAVE_X11_XKBLIB_H 1
    | #define HAVE_SSIZE_T 1
    | /* end confdefs.h.  */
    |
    |
    |       #include <vector>
    |
    | int
    | main ()
    | {
    |
    |       std::vector<int> vec;
    |       vec.push_back(0);
    |       for (auto& elt: vec) {++elt;}
    |
    |   ;
    |   return 0;
    | }
    |
    configure:7495: error: compiler does not support C++11 range-for expressions - if gcc is installed, gcc >= 4.6 required

     
  • Christoph Korn
    Christoph Korn
    2013-02-15

    This site shows some command line arguments which are required to enable the new features:
    http://gcc.gnu.org/projects/cxx0x.html

     
  • Christoph Korn
    Christoph Korn
    2013-02-15

    This patch fixed the issue for me:
    http://pastebin.com/raw.php?i=Y6JALy8v

    But configure will fail on each browser which does not have a -std=c++11 flag.

     
    • The acinclude.m4 is broken because if you do this:

      $ export CXXFLAGS="-O2 -march=native -pipe"
      $ ./configure
      $ make

      Then everything the acinclude.m4 has added to CXXFLAGS, go away, and only the ones that have been exported to the environment will be used.

      With that said, your patch looks to be part of the solution, but you missed it needs ax_check_compile_flag.m4 from autoconf-archive in m4/ subdirectory, so the full patch would be:

      --- configure.ac
      +++ configure.ac
      @@ -27,6 +27,7 @@
      AC_LANG_CPLUSPLUS dnl switch to C++
      AC_TYPE_SIZE_T
      AC_CHECK_TYPES(ssize_t)
      +AX_CHECK_COMPILE_FLAG([-std=c++11], [CXXFLAGS="$CXXFLAGS -std=c++11"])
      AC_CHECK_RANGE_FOR_SUPPORT
      AC_CHECK_LAMBDA_SUPPORT

      --- m4/ax_check_compile_flag.m4
      +++ m4/ax_check_compile_flag.m4
      @@ -0,0 +1,16 @@
      +# This macro is part of autoconf-archive with license GPL-3 or any later version
      +AC_DEFUN([AX_CHECK_COMPILE_FLAG],
      +[AC_PREREQ(2.59)dnl for _AC_LANG_PREFIX
      +AS_VAR_PUSHDEF([CACHEVAR]
      ,[ax_cv_check_[]AC_LANG_ABBREV[]flags$4_$1])dnl
      +AC_CACHE_CHECK([whether _AC_LANG compiler accepts $1], CACHEVAR,
      + ax_check_save_flags=$[
      _AC_LANG_PREFIX[]FLAGS
      + _AC_LANG_PREFIX[]FLAGS="$[]_AC_LANG_PREFIX[]FLAGS $4 $1"
      + AC_COMPILE_IFELSE([m4_default([$5],[AC_LANG_PROGRAM()])],
      + [AS_VAR_SET(CACHEVAR,[yes])],
      + [AS_VAR_SET(CACHEVAR,[no])])
      + _AC_LANG_PREFIX[]FLAGS=$ax_check_save_flags])
      +AS_IF([test x"AS_VAR_GET(CACHEVAR)" = xyes],
      + [m4_default([$2], :)],
      + [m4_default([$3], :)])
      +AS_VAR_POPDEF([CACHEVAR])dnl
      +])dnl AX_CHECK_COMPILE_FLAGS

      However, that still doesn't solve the broken acinclude.m4, so all of these get lost, at least "-fexceptions -frtti -fsigned-char -fno-check-new -pthread" for me, and the package fails to compile.

      Dunno what the acinclude.m4 source is, but the source is broken, I hope this broken macro doesn't get spread around more :(