Opened 7 years ago

Closed 6 years ago

#7066 closed task (fixed)

Implement RFC68: C++11

Reported by: Kurt Schwehr Owned by: Kurt Schwehr
Priority: normal Milestone:
Component: ConfigBuild Version: svn-trunk
Severity: normal Keywords: c++11 c++14
Cc: Mateusz Łoskot

Description

A place for discussion of implementing RFC 68: C++11 Compilation Mode.

Change History (7)

comment:1 by Kurt Schwehr, 7 years ago

I didn't like this first thing I tried. I started with just trying to remove the --with_cpp11 flag. I think it will be better to change --with_cpp11 to --with_cpp14 and have the default case enforce C++11.

To enforce C++11 (and also allow C++14), I'll add an #if in cpl_port.h that does a #error if __cplusplus is less than 201103.

I am planning to test this a pull requests so that we can work through the travis-ci builds. I will also attempt the windows builds, but I could use help.

  • gdal/configure.ac

    a b AX_CHECK_COMPILE_FLAG([-fno-operator-names], [CXX_WFLAGS="$CXX_WFLAGS -fno-opera  
    123123
    124124AC_LANG_POP([C++])
    125125
    126 CXX11_SUPPORT=no
    127 AC_ARG_WITH([cpp11],
    128             AS_HELP_STRING([--without-cpp11],
    129                [Disable C++11 compiler options]),,)
    130 
    131 AC_MSG_CHECKING([if use C++11 compiler options])
    132 if test "$with_cpp11" = "yes" -o "$with_cpp11" = "" ; then
    133     dnl Check C++ compiler compatibility with C++11
    134     AC_MSG_CHECKING([C++ compiler compatibility with C++11])
    135     AX_CXX_COMPILE_STDCXX_11([ext],[optional])
    136 
    137     if [test "$HAVE_CXX11" = "1"]; then
    138         CXX11_SUPPORT=yes
    139     fi
    140     AC_MSG_RESULT([enabled])
    141 else
    142     AC_MSG_RESULT([disabled by user])
    143 fi
    144 AC_SUBST(CXX11_SUPPORT,$CXX11_SUPPORT)
     126AC_MSG_CHECKING([C++ compiler compatibility with C++11])
     127AX_CXX_COMPILE_STDCXX_11([ext],[mandatory])
    145128
    146 if [test "$CXX11_SUPPORT" = "yes"]; then
    147     dnl Available in GCC 5.1
    148     AC_LANG_PUSH([C++])
    149         AX_CHECK_COMPILE_FLAG([-Wsuggest-override], [CXX_WFLAGS="$CXX_WFLAGS -Wsuggest-override"],,[$ERROR_ON_UNKNOWN_OPTIONS])
    150     AC_LANG_POP([C++])
    151 fi
     129dnl Available in GCC 5.1
     130AC_LANG_PUSH([C++])
     131    AX_CHECK_COMPILE_FLAG([-Wsuggest-override], [CXX_WFLAGS="$CXX_WFLAGS -Wsuggest-override"],,[$ERROR_ON_UNKNOWN_OPTIONS])
     132AC_LANG_POP([C++])
    152133
    153134dnl Enable -Wimplicit-fallthrough only if C++11 is enabled since CPL_FALLTHROUGH is only active then
    154135AC_LANG_PUSH([C++])
    SAVED_CXXFLAGS=$CXXFLAGS  
    156137CXXFLAGS="$CXXFLAGS $ERROR_ON_UNKNOWN_OPTIONS -Wimplicit-fallthrough"
    157138AC_MSG_CHECKING([if -Wimplicit-fallthrough can be enabled])
    158139AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
    159   [[#if !(__cplusplus >= 201103L && ( (defined(__clang__) && (__clang_major__ > 3 || (__clang_major__ == 3 && __clang_minor__ >=7))) || ((defined(__GNUC__) && __GNUC__ >= 7)) ) )
     140  [[#if !(( (defined(__clang__) && (__clang_major__ > 3 || (__clang_major__ == 3 && __clang_minor__ >=7))) || ((defined(__GNUC__) && __GNUC__ >= 7)) ) )
    160141    #error "not (C++11 and (clang >= 3.7 or gcc >= 7))"
    161142    #endif]])],
    162143  [CXX_WFLAGS="$CXX_WFLAGS -Wimplicit-fallthrough"]
    LOC_MSG()  
    55665547LOC_MSG([  Installation directory:    ${prefix}])
    55675548LOC_MSG([  C compiler:                ${CC} ${CFLAGS}])
    55685549LOC_MSG([  C++ compiler:              ${CXX} ${CXXFLAGS}])
    5569 LOC_MSG([  C++11 support:             ${CXX11_SUPPORT}])
    55705550LOC_MSG()
    55715551LOC_MSG([  LIBTOOL support:           ${with_libtool}])
    55725552LOC_MSG()

comment:2 by Mateusz Łoskot, 7 years ago

Cc: Mateusz Łoskot added

comment:4 by Mateusz Łoskot, 7 years ago

Kurt, FYI, my Autoconf is a bit rusty, so those changes in GEOS might not be optimal.

comment:5 by Kurt Schwehr, 7 years ago

2nd attempt still has issues, but it feels like it is on track. Need to figure out how to get python to use the correct compile flag.

https://github.com/OSGeo/gdal/pull/243/commits/9c2fa9b7939defa237c57ff0dde56f59fc98e7ed

Created a pull request to start testing with travis to see where things are at. I bet all the builds will fail. Most failed pretty quickly

trusty_clang:

/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8/cstdio:120:11: error: no member named 'gets' in the global namespace
  using ::gets;
        ~~^

mingw mingw64 python3 android:

configure: error: *** A compiler with support for C++11 language features is required.

bigendian:

In file included from gdalallregister.cpp:30:0:
/home/travis/build/OSGeo/gdal/gdal/gcore/gdal_priv.h:532:21: error: 'virtual char** GDALDataset::GetMetadata(const char*)' can be marked override [-Werror=suggest-override]
     virtual char ** GetMetadata(const char * pszDomain = "") CPL_OVERRIDE;

gcc48_stdcpp11

gcc52_stdcpp14

precise32

Last edited 7 years ago by Kurt Schwehr (previous) (diff)

comment:6 by Kurt Schwehr, 7 years ago

trusty clang:

/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8/cstdio:120:11: error: no member named 'gets' in the global namespace
  using ::gets;
        ~~^

https://stackoverflow.com/questions/24342312/clang-seems-to-use-the-gcc-libraries

You need to install libc++ and make clang use it with -stdlib=libc++

comment:7 by Even Rouault, 6 years ago

Resolution: fixed
Status: assignedclosed

C++11 requirement and related changes now committed in trunk

Note: See TracTickets for help on using tickets.