From 2a43bd305a325389cce5c5df5695cae1d0cc05b9 Mon Sep 17 00:00:00 2001 From: Roland Kaufmann Date: Wed, 24 Oct 2012 10:23:51 +0200 Subject: [PATCH 1/7] Add macros for testing C++0x/11 support in compiler These files are shamelessly ripped from dune-common/m4 (e28ca3) --- m4/cxx0x_compiler.m4 | 60 +++++++++++++++++++++++++++++++++++++++ m4/cxx0x_nullptr.m4 | 17 +++++++++++ m4/cxx0x_static_assert.m4 | 14 +++++++++ 3 files changed, 91 insertions(+) create mode 100644 m4/cxx0x_compiler.m4 create mode 100644 m4/cxx0x_nullptr.m4 create mode 100644 m4/cxx0x_static_assert.m4 diff --git a/m4/cxx0x_compiler.m4 b/m4/cxx0x_compiler.m4 new file mode 100644 index 00000000..ac8f22b9 --- /dev/null +++ b/m4/cxx0x_compiler.m4 @@ -0,0 +1,60 @@ +# whether compiler accepts -std=c++11 or -std=c++0x +# can be disabled by --disable-gxx0xcheck + +AC_DEFUN([GXX0X],[ + ac_save_CXX="$CXX" + + # try flag -std=c++11 + AC_CACHE_CHECK([whether $CXX accepts -std=c++11], dune_cv_gplusplus_accepts_cplusplus11, [ + AC_REQUIRE([AC_PROG_CXX]) + AC_ARG_ENABLE(gxx0xcheck, + AC_HELP_STRING([--disable-gxx0xcheck], + [try flag -std=c++11 to enable C++11 features [[default=yes]]]), + [gxx0xcheck=$enableval], + [gxx0xcheck=yes]) + if test "x$GXX" = xyes && test "x$gxx0xcheck" = xyes; then + AC_LANG_PUSH([C++]) + CXX="$CXX -std=c++11" + AC_TRY_COMPILE([ + #include + #include + ], [], + dune_cv_gplusplus_accepts_cplusplus11=yes, + dune_cv_gplusplus_accepts_cplusplus11=no) + AC_LANG_POP([C++]) + fi + ]) + if test "x$dune_cv_gplusplus_accepts_cplusplus11" == "xyes" ; then + CXX="$ac_save_CXX -std=c++11" + CXXCPP="$CXXCPP -std=c++11" + else + CXX="$ac_save_CXX" + + # try flag -std=c++0x instead + AC_CACHE_CHECK([whether $CXX accepts -std=c++0x], dune_cv_gplusplus_accepts_cplusplus0x, [ + AC_REQUIRE([AC_PROG_CXX]) + AC_ARG_ENABLE(gxx0xcheck, + AC_HELP_STRING([--disable-gxx0xcheck], + [try flag -std=c++0x to enable C++11 features [[default=yes]]]), + [gxx0xcheck=$enableval], + [gxx0xcheck=yes]) + if test "x$GXX" = xyes && test "x$gxx0xcheck" = xyes; then + AC_LANG_PUSH([C++]) + CXX="$CXX -std=c++0x" + AC_TRY_COMPILE([ + #include + #include + ], [], + dune_cv_gplusplus_accepts_cplusplus0x=yes, + dune_cv_gplusplus_accepts_cplusplus0x=no) + AC_LANG_POP([C++]) + fi + ]) + if test "x$dune_cv_gplusplus_accepts_cplusplus0x" == "xyes" ; then + CXX="$ac_save_CXX -std=c++0x" + CXXCPP="$CXXCPP -std=c++0x" + else + CXX="$ac_save_CXX" + fi + fi +]) diff --git a/m4/cxx0x_nullptr.m4 b/m4/cxx0x_nullptr.m4 new file mode 100644 index 00000000..5ada34a3 --- /dev/null +++ b/m4/cxx0x_nullptr.m4 @@ -0,0 +1,17 @@ +AC_DEFUN([NULLPTR_CHECK],[ + AC_CACHE_CHECK([whether nullptr is supported], dune_cv_nullptr_support, [ + AC_REQUIRE([AC_PROG_CXX]) + AC_REQUIRE([GXX0X]) + AC_LANG_PUSH([C++]) + AC_TRY_COMPILE([],[ + char* ch = nullptr; + if(ch!=nullptr) { ; } + ], + dune_cv_nullptr_support=yes, + dune_cv_nullptr_support=no) + AC_LANG_POP + ]) + if test "x$dune_cv_nullptr_support" = xyes; then + AC_DEFINE(HAVE_NULLPTR, 1, [Define to 1 if nullptr is supported]) + fi +]) diff --git a/m4/cxx0x_static_assert.m4 b/m4/cxx0x_static_assert.m4 new file mode 100644 index 00000000..1c6a7cc6 --- /dev/null +++ b/m4/cxx0x_static_assert.m4 @@ -0,0 +1,14 @@ +AC_DEFUN([STATIC_ASSERT_CHECK],[ + AC_CACHE_CHECK([whether static_assert is supported], dune_cv_static_assert_support, [ + AC_REQUIRE([AC_PROG_CXX]) + AC_REQUIRE([GXX0X]) + AC_LANG_PUSH([C++]) + AC_TRY_COMPILE([],[static_assert(true,"MSG")], + dune_cv_static_assert_support=yes, + dune_cv_static_assert_support=no) + AC_LANG_POP + ]) + if test "x$dune_cv_static_assert_support" = xyes; then + AC_DEFINE(HAVE_STATIC_ASSERT, 1, [Define to 1 if static_assert is supported]) + fi +]) From 056bce2128f1cd4680058a72e5b7be148f219468 Mon Sep 17 00:00:00 2001 From: Roland Kaufmann Date: Wed, 24 Oct 2012 10:28:48 +0200 Subject: [PATCH 2/7] Distinguish between C++0x and C++11 in conf. opts. Surely this must have been a copy&paste error. --- m4/cxx0x_compiler.m4 | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/m4/cxx0x_compiler.m4 b/m4/cxx0x_compiler.m4 index ac8f22b9..5fb27045 100644 --- a/m4/cxx0x_compiler.m4 +++ b/m4/cxx0x_compiler.m4 @@ -7,12 +7,12 @@ AC_DEFUN([GXX0X],[ # try flag -std=c++11 AC_CACHE_CHECK([whether $CXX accepts -std=c++11], dune_cv_gplusplus_accepts_cplusplus11, [ AC_REQUIRE([AC_PROG_CXX]) - AC_ARG_ENABLE(gxx0xcheck, - AC_HELP_STRING([--disable-gxx0xcheck], + AC_ARG_ENABLE(gxx11check, + AC_HELP_STRING([--disable-gxx11check], [try flag -std=c++11 to enable C++11 features [[default=yes]]]), - [gxx0xcheck=$enableval], - [gxx0xcheck=yes]) - if test "x$GXX" = xyes && test "x$gxx0xcheck" = xyes; then + [gxx11check=$enableval], + [gxx11check=yes]) + if test "x$GXX" = xyes && test "x$gxx11check" = xyes; then AC_LANG_PUSH([C++]) CXX="$CXX -std=c++11" AC_TRY_COMPILE([ From 6d2f7e1f7c3a15f21afde31b13b5ca2fd788cf2d Mon Sep 17 00:00:00 2001 From: Roland Kaufmann Date: Wed, 24 Oct 2012 10:32:23 +0200 Subject: [PATCH 3/7] Compile with C++0x support if possible Since DUNE does this, it might a good idea to track the same ABI. --- m4/opm_core.m4 | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/m4/opm_core.m4 b/m4/opm_core.m4 index 40e1b7c5..a5b24a0c 100644 --- a/m4/opm_core.m4 +++ b/m4/opm_core.m4 @@ -5,6 +5,11 @@ dnl -*- autoconf -*- AC_DEFUN([OPM_CORE_CHECKS], [ +# Language features +GXX0X +STATIC_ASSERT_CHECK +NULLPTR_CHECK + # Checks for libraries. # Bring in numerics support (standard library component) From 9063a470516e1d0520e205145604a37555e112c7 Mon Sep 17 00:00:00 2001 From: Roland Kaufmann Date: Wed, 24 Oct 2012 11:25:28 +0200 Subject: [PATCH 4/7] Disable checks for C++11 if C++0x is disabled By adding an extra test we can avoid the somehow illogical possibility of building with '--enable-gxx11check --disable-gxx0xcheck'. --- m4/cxx0x_compiler.m4 | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/m4/cxx0x_compiler.m4 b/m4/cxx0x_compiler.m4 index 5fb27045..11089940 100644 --- a/m4/cxx0x_compiler.m4 +++ b/m4/cxx0x_compiler.m4 @@ -3,16 +3,23 @@ AC_DEFUN([GXX0X],[ ac_save_CXX="$CXX" - + + # put this check first, so we get disable C++11 if C++0x is + AC_ARG_ENABLE(gxx0xcheck, + AC_HELP_STRING([--disable-gxx0xcheck], + [try flag -std=c++0x to enable C++0x features [[default=yes]]]), + [gxx0xcheck=$enableval], + [gxx0xcheck=yes]) + AC_ARG_ENABLE(gxx11check, + AC_HELP_STRING([--disable-gxx11check], + [try flag -std=c++11 to enable C++11 features [[default=yes]]]), + [gxx11check=$enableval], + [gxx11check=yes]) + # try flag -std=c++11 AC_CACHE_CHECK([whether $CXX accepts -std=c++11], dune_cv_gplusplus_accepts_cplusplus11, [ AC_REQUIRE([AC_PROG_CXX]) - AC_ARG_ENABLE(gxx11check, - AC_HELP_STRING([--disable-gxx11check], - [try flag -std=c++11 to enable C++11 features [[default=yes]]]), - [gxx11check=$enableval], - [gxx11check=yes]) - if test "x$GXX" = xyes && test "x$gxx11check" = xyes; then + if test "x$GXX" = xyes && test "x$gxx11check" = xyes && test "x$gxx0xcheck" = xyes ; then AC_LANG_PUSH([C++]) CXX="$CXX -std=c++11" AC_TRY_COMPILE([ @@ -22,6 +29,8 @@ AC_DEFUN([GXX0X],[ dune_cv_gplusplus_accepts_cplusplus11=yes, dune_cv_gplusplus_accepts_cplusplus11=no) AC_LANG_POP([C++]) + else + dune_cv_gplusplus_accepts_cplusplus11=disabled fi ]) if test "x$dune_cv_gplusplus_accepts_cplusplus11" == "xyes" ; then @@ -33,11 +42,6 @@ AC_DEFUN([GXX0X],[ # try flag -std=c++0x instead AC_CACHE_CHECK([whether $CXX accepts -std=c++0x], dune_cv_gplusplus_accepts_cplusplus0x, [ AC_REQUIRE([AC_PROG_CXX]) - AC_ARG_ENABLE(gxx0xcheck, - AC_HELP_STRING([--disable-gxx0xcheck], - [try flag -std=c++0x to enable C++11 features [[default=yes]]]), - [gxx0xcheck=$enableval], - [gxx0xcheck=yes]) if test "x$GXX" = xyes && test "x$gxx0xcheck" = xyes; then AC_LANG_PUSH([C++]) CXX="$CXX -std=c++0x" @@ -48,6 +52,8 @@ AC_DEFUN([GXX0X],[ dune_cv_gplusplus_accepts_cplusplus0x=yes, dune_cv_gplusplus_accepts_cplusplus0x=no) AC_LANG_POP([C++]) + else + dune_cv_gplusplus_accepts_cplusplus0x=disabled fi ]) if test "x$dune_cv_gplusplus_accepts_cplusplus0x" == "xyes" ; then From bb96a2e2699f241f1a6661f039fb82271161baca Mon Sep 17 00:00:00 2001 From: Roland Kaufmann Date: Wed, 24 Oct 2012 11:39:51 +0200 Subject: [PATCH 5/7] Refrain from using reserved names ac_* for variables --- m4/cxx0x_compiler.m4 | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/m4/cxx0x_compiler.m4 b/m4/cxx0x_compiler.m4 index 11089940..0eb3b5c9 100644 --- a/m4/cxx0x_compiler.m4 +++ b/m4/cxx0x_compiler.m4 @@ -2,7 +2,7 @@ # can be disabled by --disable-gxx0xcheck AC_DEFUN([GXX0X],[ - ac_save_CXX="$CXX" + save_CXX="$CXX" # put this check first, so we get disable C++11 if C++0x is AC_ARG_ENABLE(gxx0xcheck, @@ -34,10 +34,10 @@ AC_DEFUN([GXX0X],[ fi ]) if test "x$dune_cv_gplusplus_accepts_cplusplus11" == "xyes" ; then - CXX="$ac_save_CXX -std=c++11" + CXX="$save_CXX -std=c++11" CXXCPP="$CXXCPP -std=c++11" else - CXX="$ac_save_CXX" + CXX="$save_CXX" # try flag -std=c++0x instead AC_CACHE_CHECK([whether $CXX accepts -std=c++0x], dune_cv_gplusplus_accepts_cplusplus0x, [ @@ -57,10 +57,10 @@ AC_DEFUN([GXX0X],[ fi ]) if test "x$dune_cv_gplusplus_accepts_cplusplus0x" == "xyes" ; then - CXX="$ac_save_CXX -std=c++0x" + CXX="$save_CXX -std=c++0x" CXXCPP="$CXXCPP -std=c++0x" else - CXX="$ac_save_CXX" + CXX="$save_CXX" fi fi ]) From e8444f91e03e79964868c54b184bd0143663c9b8 Mon Sep 17 00:00:00 2001 From: Roland Kaufmann Date: Wed, 24 Oct 2012 12:01:38 +0200 Subject: [PATCH 6/7] Replace deprecated AC_TRY_COMPILE with AC_COMPILE_IFELSE --- m4/cxx0x_compiler.m4 | 16 ++++++++-------- m4/cxx0x_nullptr.m4 | 8 ++++---- m4/cxx0x_static_assert.m4 | 6 +++--- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/m4/cxx0x_compiler.m4 b/m4/cxx0x_compiler.m4 index 0eb3b5c9..c3509b85 100644 --- a/m4/cxx0x_compiler.m4 +++ b/m4/cxx0x_compiler.m4 @@ -22,12 +22,12 @@ AC_DEFUN([GXX0X],[ if test "x$GXX" = xyes && test "x$gxx11check" = xyes && test "x$gxx0xcheck" = xyes ; then AC_LANG_PUSH([C++]) CXX="$CXX -std=c++11" - AC_TRY_COMPILE([ + AC_COMPILE_IFELSE([AC_LANG_PROGRAM([ #include #include - ], [], - dune_cv_gplusplus_accepts_cplusplus11=yes, - dune_cv_gplusplus_accepts_cplusplus11=no) + ],)], + [dune_cv_gplusplus_accepts_cplusplus11=yes], + [dune_cv_gplusplus_accepts_cplusplus11=no]) AC_LANG_POP([C++]) else dune_cv_gplusplus_accepts_cplusplus11=disabled @@ -45,12 +45,12 @@ AC_DEFUN([GXX0X],[ if test "x$GXX" = xyes && test "x$gxx0xcheck" = xyes; then AC_LANG_PUSH([C++]) CXX="$CXX -std=c++0x" - AC_TRY_COMPILE([ + AC_COMPILE_IFELSE([AC_LANG_PROGRAM([ #include #include - ], [], - dune_cv_gplusplus_accepts_cplusplus0x=yes, - dune_cv_gplusplus_accepts_cplusplus0x=no) + ],)], + [dune_cv_gplusplus_accepts_cplusplus0x=yes], + [dune_cv_gplusplus_accepts_cplusplus0x=no]) AC_LANG_POP([C++]) else dune_cv_gplusplus_accepts_cplusplus0x=disabled diff --git a/m4/cxx0x_nullptr.m4 b/m4/cxx0x_nullptr.m4 index 5ada34a3..18d44451 100644 --- a/m4/cxx0x_nullptr.m4 +++ b/m4/cxx0x_nullptr.m4 @@ -3,12 +3,12 @@ AC_DEFUN([NULLPTR_CHECK],[ AC_REQUIRE([AC_PROG_CXX]) AC_REQUIRE([GXX0X]) AC_LANG_PUSH([C++]) - AC_TRY_COMPILE([],[ + AC_COMPILE_IFELSE([AC_LANG_PROGRAM(,[ char* ch = nullptr; if(ch!=nullptr) { ; } - ], - dune_cv_nullptr_support=yes, - dune_cv_nullptr_support=no) + ])], + [dune_cv_nullptr_support=yes], + [dune_cv_nullptr_support=no]) AC_LANG_POP ]) if test "x$dune_cv_nullptr_support" = xyes; then diff --git a/m4/cxx0x_static_assert.m4 b/m4/cxx0x_static_assert.m4 index 1c6a7cc6..b68d155b 100644 --- a/m4/cxx0x_static_assert.m4 +++ b/m4/cxx0x_static_assert.m4 @@ -3,9 +3,9 @@ AC_DEFUN([STATIC_ASSERT_CHECK],[ AC_REQUIRE([AC_PROG_CXX]) AC_REQUIRE([GXX0X]) AC_LANG_PUSH([C++]) - AC_TRY_COMPILE([],[static_assert(true,"MSG")], - dune_cv_static_assert_support=yes, - dune_cv_static_assert_support=no) + AC_COMPILE_IFELSE([AC_LANG_PROGRAM(,[static_assert(true,"MSG")])], + [dune_cv_static_assert_support=yes], + [dune_cv_static_assert_support=no]) AC_LANG_POP ]) if test "x$dune_cv_static_assert_support" = xyes; then From 09f458f5ee7bacab419caa191fb50d837521b12a Mon Sep 17 00:00:00 2001 From: Roland Kaufmann Date: Wed, 24 Oct 2012 21:14:24 +0200 Subject: [PATCH 7/7] Remove superfluous construction by std::make_pair Since we know the type of the components, we may just as well create the pair directly! (Using make_pair invokes compiler bugs in GCC). --- opm/core/wells/WellsGroup.cpp | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/opm/core/wells/WellsGroup.cpp b/opm/core/wells/WellsGroup.cpp index e1bed0cb..8c541431 100644 --- a/opm/core/wells/WellsGroup.cpp +++ b/opm/core/wells/WellsGroup.cpp @@ -762,27 +762,16 @@ namespace Opm } } -// macro to insert const_cast to get a round bug in GCC 4.6.3 where it -// suddenly believes that "this" is a const pointer, although we are not -// in a const method. -#if ( __GNUC__ == 4 ) && ( __GNUC_MINOR__ == 6 ) && ( __GNUC_PATCHLEVEL__ == 3 ) -#define CONST_CAST(T,v) const_cast(v) -#else -#define CONST_CAST(T,v) v -#endif - std::pair WellNode::getWorstOffending(const std::vector& well_reservoirrates_phase, const std::vector& well_surfacerates_phase, ProductionSpecification::ControlMode mode) { const int np = phaseUsage().num_phases; const int index = self_index_*np; - // note: CONST_CAST is just to work around a bug in GCC 4.6.3; it - // is not really needed, and should be a harmless no-op. - return std::make_pair(CONST_CAST(WellNode*,this), - rateByMode(&well_reservoirrates_phase[index], - &well_surfacerates_phase[index], - mode)); + return std::pair(this, + rateByMode(&well_reservoirrates_phase[index], + &well_surfacerates_phase[index], + mode)); } void WellNode::applyInjGroupControl(const InjectionSpecification::ControlMode control_mode,