]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Fix the remaining gcc-8 warnings 6475/head
authorDaniel Arndt <daniel.arndt@iwr.uni-heidelberg.de>
Sat, 5 May 2018 00:29:04 +0000 (02:29 +0200)
committerDaniel Arndt <daniel.arndt@iwr.uni-heidelberg.de>
Sun, 6 May 2018 21:59:12 +0000 (23:59 +0200)
cmake/checks/check_01_cxx_features.cmake
include/deal.II/base/config.h.in
include/deal.II/base/partitioner.templates.h
include/deal.II/base/utilities.h
include/deal.II/lac/sparse_matrix.templates.h
include/deal.II/lac/vector_operations_internal.h

index 139673ac3fda08afb348932553abb187433006f4..6c4b9733814dc6367d0fca55d34a3b0b136d1e54 100644 (file)
@@ -129,6 +129,7 @@ IF(NOT DEFINED DEAL_II_WITH_CXX17 OR DEAL_II_WITH_CXX17)
     UNSET_IF_CHANGED(CHECK_CXX_FEATURES_FLAGS_CXX17_SAVED
       "${CMAKE_REQUIRED_FLAGS}${DEAL_II_CXX_VERSION_FLAG}"
       DEAL_II_HAVE_CXX17_ATTRIBUTES
+      DEAL_II_HAVE_CXX17_IF_CONSTEXPR
       )
 
     #
@@ -160,10 +161,26 @@ IF(NOT DEFINED DEAL_II_WITH_CXX17 OR DEAL_II_WITH_CXX17)
       "
       DEAL_II_HAVE_CXX17_ATTRIBUTES)
 
+    #
+    # Test that the c++17 if constexpr is supported.
+    #
+    CHECK_CXX_SOURCE_COMPILES(
+      "
+      int main()
+      {
+        constexpr bool flag = false;
+        if constexpr(flag)
+          return 1;
+        return 0;
+      }
+      "
+      DEAL_II_HAVE_CXX17_IF_CONSTEXPR)
+
     RESET_CMAKE_REQUIRED()
   ENDIF()
 
-  IF( DEAL_II_HAVE_CXX17_ATTRIBUTES )
+  IF( DEAL_II_HAVE_CXX17_ATTRIBUTES AND
+      DEAL_II_HAVE_CXX17_IF_CONSTEXPR)
     SET(DEAL_II_HAVE_CXX17 TRUE)
   ELSE()
     IF(NOT _user_provided_cxx_version_flag)
index 383ad47fac1c827ab154f490417396ed87d40016..38cbfbf06152f2e50c6abdf768413f89f6d81c77 100644 (file)
@@ -40,6 +40,7 @@
 #cmakedefine DEAL_II_WITH_ASSIMP
 #cmakedefine DEAL_II_WITH_CUDA
 #cmakedefine DEAL_II_WITH_CXX14
+#cmakedefine DEAL_II_WITH_CXX17
 #cmakedefine DEAL_II_WITH_GSL
 #cmakedefine DEAL_II_WITH_GMSH
 #cmakedefine DEAL_II_WITH_HDF5
index dbc5ce7daa7baed5e1ed7d3bfb426e6d12f46496..d10066bc952428fbbd78748335d0cf106cfb1b01 100644 (file)
@@ -335,7 +335,14 @@ namespace Utilities
                                   "vector_operation argument was passed to "
                                   "import_from_ghosted_array_start as is passed "
                                   "to import_from_ghosted_array_finish."));
-          std::memset(ghost_array.data(), 0, sizeof(Number)*ghost_array.size());
+#ifdef DEAL_II_WITH_CXX17
+          if constexpr (std::is_trivial<Number>::value)
+#else
+          if (std::is_trivial<Number>::value)
+#endif
+            std::memset(ghost_array.data(), 0, sizeof(Number)*ghost_array.size());
+          else
+            std::fill(ghost_array.data(), ghost_array.data()+ghost_array.size(), 0);
           return;
         }
 #endif
@@ -407,7 +414,14 @@ namespace Utilities
       if (ghost_array.size()>0)
         {
           Assert(ghost_array.begin()!=nullptr, ExcInternalError());
-          std::memset(ghost_array.data(), 0, sizeof(Number)*n_ghost_indices());
+#ifdef DEAL_II_WITH_CXX17
+          if constexpr (std::is_trivial<Number>::value)
+#else
+          if (std::is_trivial<Number>::value)
+#endif
+            std::memset(ghost_array.data(), 0, sizeof(Number)*n_ghost_indices());
+          else
+            std::fill(ghost_array.data(), ghost_array.data()+n_ghost_indices(), 0);
         }
 
       // clear the compress requests
index ad70c706ace96144110d1512e0832f126aac2565..5f73b77b38cdb0798894561280ef59c48d4d6aa6 100644 (file)
@@ -1009,14 +1009,15 @@ namespace Utilities
     // we have to work around the fact that GCC 4.8.x claims to be C++
     // conforming, but is not actually as it does not implement
     // std::is_trivially_copyable.
-    if (
 #if __GNUG__ && __GNUC__ < 5
-      __has_trivial_copy(T)
+    if (  __has_trivial_copy(T) && sizeof(T)<256)
 #else
-      std::is_trivially_copyable<T>()
+#  ifdef DEAL_II_WITH_CXX17
+    if constexpr (std::is_trivially_copyable<T>() && sizeof(T)<256)
+#  else
+    if (std::is_trivially_copyable<T>() && sizeof(T)<256)
+#  endif
 #endif
-      &&
-      sizeof(T)<256)
       {
         const size_t previous_size = dest_buffer.size();
         dest_buffer.resize (previous_size + sizeof(T));
@@ -1076,14 +1077,15 @@ namespace Utilities
     // we have to work around the fact that GCC 4.8.x claims to be C++
     // conforming, but is not actually as it does not implement
     // std::is_trivially_copyable.
-    if (
 #if __GNUG__ && __GNUC__ < 5
-      __has_trivial_copy(T)
+    if (  __has_trivial_copy(T) && sizeof(T)<256)
 #else
-      std::is_trivially_copyable<T>()
+#  ifdef DEAL_II_WITH_CXX17
+    if constexpr (std::is_trivially_copyable<T>() && sizeof(T)<256)
+#  else
+    if (std::is_trivially_copyable<T>() && sizeof(T)<256)
+#  endif
 #endif
-      &&
-      sizeof(T)<256)
       {
         Assert (std::distance(cbegin, cend) == sizeof(T), ExcInternalError());
         T object;
index 70c7fb191e7f62f6c3e750a6765a33ad76e279de..6761c3d8ab44fbd7d5ce543b748a56321cef1c52 100644 (file)
@@ -221,7 +221,16 @@ SparseMatrix<number>::operator = (const double d)
                                             val.get()),
                                   grain_size);
   else if (matrix_size > 0)
-    std::memset (val.get(), 0, matrix_size*sizeof(number));
+    {
+#ifdef DEAL_II_WITH_CXX17
+      if constexpr(std::is_trivial<number>::value)
+#else
+      if (std::is_trivial<number>::value)
+#endif
+        std::memset (val.get(), 0, matrix_size*sizeof(number));
+      else
+        std::fill (val.get(), val.get()+matrix_size, 0);
+    }
 
   return *this;
 }
index b1999069c97ee526794711218c0e3b716413a873..713d792ca3348dec338266c934fd1f7704af3521 100644 (file)
@@ -212,9 +212,18 @@ namespace internal
         Assert (end>=begin, ExcInternalError());
 
         if (value == Number())
-          std::memset (dst+begin,0,(end-begin)*sizeof(Number));
-        else
-          std::fill (dst+begin, dst+end, value);
+          {
+#ifdef DEAL_II_WITH_CXX17
+            if constexpr (std::is_trivial<Number>::value)
+#else
+            if (std::is_trivial<Number>::value)
+#endif
+              {
+                std::memset(dst+begin, 0, sizeof(Number)*(end-begin));
+                return;
+              }
+          }
+        std::fill (dst+begin, dst+end, value);
       }
 
       const Number value;
@@ -237,7 +246,15 @@ namespace internal
       {
         Assert (end>=begin, ExcInternalError());
 
-        if (std::is_same<Number,OtherNumber>::value)
+#if __GNUG__ && __GNUC__ < 5
+        if (  __has_trivial_copy(Number) && std::is_same<Number,OtherNumber>::value)
+#else
+#  ifdef DEAL_II_WITH_CXX17
+        if constexpr (std::is_trivially_copyable<Number>()  && std::is_same<Number,OtherNumber>::value)
+#  else
+        if (std::is_trivially_copyable<Number>() && std::is_same<Number,OtherNumber>::value)
+#  endif
+#endif
           std::memcpy(dst+begin, src+begin, (end-begin)*sizeof(Number));
         else
           {

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.