Skip to content

Commit

Permalink
Enable c++11 syntax.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
GiovanniBussi committed Feb 22, 2017
1 parent 549bd3b commit 2ac6e1a
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 18 deletions.
5 changes: 0 additions & 5 deletions .travis.yml
Expand Up @@ -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
Expand Down
21 changes: 13 additions & 8 deletions configure
Expand Up @@ -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. */
Expand Down Expand Up @@ -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 ()
{
Expand All @@ -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
Expand Down
14 changes: 10 additions & 4 deletions configure.ac
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion src/maketools/codecheck
Expand Up @@ -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
Expand Down

0 comments on commit 2ac6e1a

Please sign in to comment.