]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Introduce two macros to guard external header files
authorMatthias Maier <tamiko@43-1.org>
Fri, 17 Apr 2015 22:24:38 +0000 (00:24 +0200)
committerMatthias Maier <tamiko@43-1.org>
Fri, 17 Apr 2015 22:45:37 +0000 (00:45 +0200)
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.

cmake/checks/check_01_compiler_features.cmake
include/deal.II/base/config.h.in

index b6fa9c02276dd6809e2f0acdae7592b90553f006..dba3a8673536ca484454cea80b6f6ce3bf8961dc 100644 (file)
@@ -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()
+
index fda7109f589ca120403d1a6b6689579ec8486946..81da0b3ccd6157494989ff7cfacda34a89112a28 100644 (file)
 #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
 
 
 /***********************************************************************
 
 /***********************************************************************
  * 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.
  */
 
 /*
  *  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 + \
 #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:
  */

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.