]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Detect unused variables and unused functions with clang
authorDaniel Arndt <daniel.arndt@iwr.uni-heidelberg.de>
Sun, 22 Oct 2017 13:12:30 +0000 (15:12 +0200)
committerDaniel Arndt <daniel.arndt@iwr.uni-heidelberg.de>
Sun, 22 Oct 2017 14:07:31 +0000 (16:07 +0200)
cmake/setup_compiler_flags_gnu.cmake
source/dummy.cc

index 04a3761c22528157a95ca8fab7f2804a12cc4794..53f22908727fddaaff35be1b2ce8f9cf0192f5e4 100644 (file)
@@ -94,7 +94,6 @@ IF(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
   ENABLE_IF_SUPPORTED(DEAL_II_CXX_FLAGS "-Wno-unsupported-friend")
 
   ENABLE_IF_SUPPORTED(DEAL_II_CXX_FLAGS "-Wno-unused-parameter")
-  ENABLE_IF_SUPPORTED(DEAL_II_CXX_FLAGS "-Wno-unused-variable")
 
   #
   # Disable a diagnostic that warns about potentially uninstantiated static
@@ -106,12 +105,18 @@ IF(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
   # Clang versions prior to 3.6 emit a lot of false positives wrt
   # "-Wunused-function". Also suppress warnings for Xcode older than 6.3
   # (which is equivalent to clang < 3.6).
-  #
-  # FIXME: I wait for the day with a clang version "4.0"... and I will
-  # curse the person that thought it is a _great_ idea to come up with
-  # independent version numbers for clang on Mac...
-  #
-  IF( CMAKE_CXX_COMPILER_VERSION VERSION_LESS "3.6" OR
+  # Policy CMP0025 allows to differentiate between Clang and AppleClang
+  # which admits a more fine-grained control. Otherwise, we are left
+  # with just disabling this feature for all versions between 4.0 and 6.3.
+  #
+  IF (POLICY CMP0025)
+    IF( (CMAKE_CXX_COMPILER_ID STREQUAL "Clang"
+         AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS "3.6")
+        OR (CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang"
+         AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS "6.3"))
+      ENABLE_IF_SUPPORTED(DEAL_II_CXX_FLAGS "-Wno-unused-function")
+    ENDIF()
+  ELSEIF(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "3.6" OR
       ( NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS "4.0" AND
         CMAKE_CXX_COMPILER_VERSION VERSION_LESS "6.3") )
     ENABLE_IF_SUPPORTED(DEAL_II_CXX_FLAGS "-Wno-unused-function")
index 37ebf06eb0c8080699f49c0283a20cbb40db6c40..19ae7b02a46fa9d8cbbcb8f8043b8438631de1d0 100644 (file)
@@ -21,4 +21,7 @@
  */
 
 const int global_symbol_42 = 42;
-
+void use_global_symbol_42()
+{
+  (void) global_symbol_42;
+}

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.