From: Matthias Maier Date: Fri, 17 Apr 2015 22:24:38 +0000 (+0200) Subject: Introduce two macros to guard external header files X-Git-Tag: v8.3.0-rc1~249^2~2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b1ac301ee9ae941fedb5d602b81e57bb7858411e;p=dealii.git Introduce two macros to guard external header files This utilizes the "GCC diagnostic" pragma with the corresponding "push" and "pop" mechanism, as well as the "ignored" statement to selectively disable specific diagnostic categories. --- diff --git a/cmake/checks/check_01_compiler_features.cmake b/cmake/checks/check_01_compiler_features.cmake index b6fa9c0227..dba3a86735 100644 --- a/cmake/checks/check_01_compiler_features.cmake +++ b/cmake/checks/check_01_compiler_features.cmake @@ -1,6 +1,6 @@ ## --------------------------------------------------------------------- ## -## Copyright (C) 2012 - 2014 by the deal.II authors +## Copyright (C) 2012 - 2015 by the deal.II authors ## ## This file is part of the deal.II library. ## @@ -82,7 +82,7 @@ CHECK_CXX_COMPILER_BUG( # # Check for existence of the __builtin_expect facility of newer -# gcc compilers. This can be used to hint the compiler's branch +# GCC compilers. This can be used to hint the compiler's branch # prediction unit in some cases. We use it in the AssertThrow # macros. # @@ -97,7 +97,7 @@ CHECK_CXX_SOURCE_COMPILES( # -# Newer versions of gcc have a very nice feature: you can set +# Newer versions of GCC have a very nice feature: you can set # a verbose terminate handler, that not only aborts a program # when an exception is thrown and not caught somewhere, but # before aborting it prints that an exception has been thrown, @@ -204,7 +204,7 @@ CHECK_CXX_SOURCE_COMPILES( # -# Gcc and some other compilers have __PRETTY_FUNCTION__, showing +# GCC and some other compilers have __PRETTY_FUNCTION__, showing # an unmangled version of the function we are presently in, # while __FUNCTION__ (or __func__ in ISO C99) simply give the # function name which would not include the arguments of that @@ -252,7 +252,7 @@ ENDIF() # -# Newer versions of gcc can pass a flag to the assembler to +# Newer versions of GCC can pass a flag to the assembler to # compress debug sections. At the time of writing this test, # this can save around 230 MB of disk space on the object # files we produce (810MB down to 570MB for the debug versions @@ -281,7 +281,7 @@ ENDIF() # -# Gcc and some other compilers have an attribute of the form +# GCC and some other compilers have an attribute of the form # __attribute__((deprecated)) that can be used to make the # compiler warn whenever a deprecated function is used. See # if this attribute is available. @@ -313,3 +313,23 @@ ELSE() SET(DEAL_II_DEPRECATED " ") ENDIF() + +# +# GCC and Clang allow fine grained control of diagnostics via the "GCC +# diagnostic" pragma. Check whether the compiler supports the "push" and +# "pop" mechanism and the "ignored" toggle. Further, test for the +# alternative "_Pragma(...)" variant (and that it does not emit a warning). +# +# - Matthias Maier, 2015 +# +PUSH_CMAKE_REQUIRED("-Werror") +CHECK_CXX_SOURCE_COMPILES( + " + _Pragma(\"GCC diagnostic push\") + _Pragma(\"GCC diagnostic ignored \\\\\\\"-Wextra\\\\\\\"\") + int main() { return 0; } + _Pragma(\"GCC diagnostic pop\") + " + DEAL_II_COMPILER_HAS_DIAGNOSTIC_PRAGMA) +RESET_CMAKE_REQUIRED() + diff --git a/include/deal.II/base/config.h.in b/include/deal.II/base/config.h.in index fda7109f58..81da0b3ccd 100644 --- a/include/deal.II/base/config.h.in +++ b/include/deal.II/base/config.h.in @@ -17,15 +17,6 @@ #define __deal2__config_h -/*********************************************************************** - * Two macro names that we put at the top and bottom of all deal.II files - * and that will be expanded to "namespace dealii {" and "}". - */ - -#define DEAL_II_NAMESPACE_OPEN namespace dealii { -#define DEAL_II_NAMESPACE_CLOSE } - - /*********************************************************************** * Information about deal.II: */ @@ -93,6 +84,7 @@ #cmakedefine DEAL_II_HAVE_LIBSTDCXX_DEMANGLER #cmakedefine __PRETTY_FUNCTION__ @__PRETTY_FUNCTION__@ #cmakedefine DEAL_II_DEPRECATED @DEAL_II_DEPRECATED@ +#cmakedefine DEAL_II_COMPILER_HAS_DIAGNOSTIC_PRAGMA /*********************************************************************** @@ -184,6 +176,9 @@ /*********************************************************************** * Various macros for version number query and comparison: + * + * These macros are defined to make testing for specific versions within + * the deal.II main code as simple as possible. */ /* @@ -241,18 +236,6 @@ * PETSC_USE_COMPLEX */ -/* - * These macros are defined to make testing for PETSc versions within - * the deal.II main code as simple as possible. In brief they are used - * like this: (i) DEAL_II_PETSC_VERSION_LT is used to advance the - * PETScWrappers to newer versions of PETSc while preserving backward - * compatibility; and (ii) DEAL_II_PETSC_VERSION_GTE is used to add - * functionality to the PETScWrappers that does not exist in previous - * versions of PETSc. Examples of usage can be found in - * lac/source/petsc_matrix_base.h. Note: SLEPcWrappers do not need - * their own analogical macros, since SLEPc and PETSc must have - * identical version numbers anyways. - */ #define DEAL_II_PETSC_VERSION_LT(major,minor,subminor) \ ((PETSC_VERSION_MAJOR * 10000 + \ PETSC_VERSION_MINOR * 100 + \ @@ -285,6 +268,44 @@ #endif +/*********************************************************************** + * Two macro names that we put at the top and bottom of all deal.II files + * and that will be expanded to "namespace dealii {" and "}". + */ + +#define DEAL_II_NAMESPACE_OPEN namespace dealii { +#define DEAL_II_NAMESPACE_CLOSE } + + +/*********************************************************************** + * Two macros to guard external header includes. + * + * Selectively disable diagnostics set by "-Wextra" (and similar flags) for + * GCC and compiler accepting GCC dialects (such as clang). + * "diagnostic push" is supported since gcc-4.6 and clang-3.3. + */ + +#ifdef DEAL_II_COMPILER_HAS_DIAGNOSTIC_PRAGMA + +# define DEAL_II_DISABLE_EXTRA_DIAGNOSTICS \ +_Pragma("GCC diagnostic push") \ +_Pragma("GCC diagnostic ignored \"-Wextra\"") \ +_Pragma("GCC diagnostic ignored \"-Woverloaded-virtual\"") \ +_Pragma("GCC diagnostic ignored \"-Wunused-function\"") \ +_Pragma("GCC diagnostic ignored \"-Wunused-parameter\"") \ +_Pragma("GCC diagnostic ignored \"-Wunused-variable\"") + +# define DEAL_II_ENABLE_EXTRA_DIAGNOSTICS \ +_Pragma("GCC diagnostic pop") + +#else + +# define DEAL_II_DISABLE_EXTRA_DIAGNOSTICS +# define DEAL_II_ENABLE_EXTRA_DIAGNOSTICS + +#endif + + /*********************************************************************** * Final inclusions: */