From 2ac6e1adb2789da327ba8225a14f74c1fd7c3594 Mon Sep 17 00:00:00 2001 From: Giovanni Bussi <giovanni.bussi@gmail.com> Date: Wed, 22 Feb 2017 09:22:41 +0100 Subject: [PATCH] Enable c++11 syntax. This requires a few fixes: - Replace -ansi with -std=c++11 in autoconf. - Add a check that c++11 is supported in autoconf. - Change flags for cppcheck. - Remove travis configurations that would fail. Additionally, I removed the check for 'explicit' keyword, which is not needed with C++11. Fixes #212 --- .travis.yml | 5 ----- configure | 21 +++++++++++++-------- configure.ac | 14 ++++++++++---- src/maketools/codecheck | 2 +- 4 files changed, 24 insertions(+), 18 deletions(-) diff --git a/.travis.yml b/.travis.yml index b86634a23..8f095c34f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -30,11 +30,6 @@ matrix: dist: trusty sudo: required env: PLUMED_CC=gcc PLUMED_CXX=g++ PLUMED_CXXFLAGS=-O3 LAPACK=yes -# then I try serial compiler on UBUNTU precise - - os: linux - dist: precise - sudo: required - env: PLUMED_CC=gcc PLUMED_CXX=g++ # test using external blas with internal lapack - os: linux dist: trusty diff --git a/configure b/configure index eda363efc..0b4f7aef7 100755 --- a/configure +++ b/configure @@ -4443,9 +4443,9 @@ rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext save_CXXFLAGS="$CXXFLAGS" - CXXFLAGS="$CXXFLAGS -ansi" - { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CXX accepts -ansi" >&5 -$as_echo_n "checking whether $CXX accepts -ansi... " >&6; } + CXXFLAGS="$CXXFLAGS -std=c++11" + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CXX accepts -std=c++11" >&5 +$as_echo_n "checking whether $CXX accepts -std=c++11... " >&6; } cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ @@ -5056,11 +5056,15 @@ rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CXX supports explicit" >&5 -$as_echo_n "checking whether $CXX supports explicit... " >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CXX declares c++11 support" >&5 +$as_echo_n "checking whether $CXX declares c++11 support... " >&6; } cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ - class A{explicit A(){}}; + +#if __cplusplus <= 199711L +this_compiler_does_not_support_cxx11 +#endif + int main () { @@ -5075,13 +5079,14 @@ $as_echo "yes" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } ; - $as_echo "#define explicit /**/" >>confdefs.h - + as_fn_error $? "C++11 support is required" "$LINENO" 5 fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + + if test "$dependency_tracking" = true then { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CXX can generate dependency file with -MM -MF" >&5 diff --git a/configure.ac b/configure.ac index b9ecf5bec..be80486cd 100644 --- a/configure.ac +++ b/configure.ac @@ -252,7 +252,7 @@ if test $basic_warnings == true then PLUMED_CHECK_CXXFLAG([-Wall]) PLUMED_CHECK_CXXFLAG([-pedantic]) - PLUMED_CHECK_CXXFLAG([-ansi]) + PLUMED_CHECK_CXXFLAG([-std=c++11]) fi if test $debug == true @@ -282,11 +282,17 @@ then PLUMED_CHECK_CXXFLAG([-Wold-style-cast]) fi -AC_MSG_CHECKING([whether $CXX supports explicit]) -AC_COMPILE_IFELSE([AC_LANG_PROGRAM([ class A{explicit A(){}};])], +AC_MSG_CHECKING([whether $CXX declares c++11 support]) +AC_COMPILE_IFELSE([AC_LANG_PROGRAM([ +#if __cplusplus <= 199711L +this_compiler_does_not_support_cxx11 +#endif +])], [AC_MSG_RESULT([yes])], [AC_MSG_RESULT([no]) ; - AC_DEFINE([explicit],[])]) + AC_MSG_ERROR([C++11 support is required])]) + + AC_SUBST(disable_dependency_tracking) diff --git a/src/maketools/codecheck b/src/maketools/codecheck index 15b6bd2f2..89781a371 100755 --- a/src/maketools/codecheck +++ b/src/maketools/codecheck @@ -34,7 +34,7 @@ if [ $do_cppcheck == true ] ; then else files="$(echo */*.{h,cpp})" fi - cppcheck --std=c++03 --std=posix 4 -j 4 --platform=unix64 \ + cppcheck --std=c++11 --std=posix 4 -j 4 --platform=unix64 \ --template='[{file}:{line}] ({severity}) :{id}: {message}' --enable=all --inline-suppr --force \ $files fi -- GitLab