]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Workaround for a bug in gcc-4.8 wrt to operator* and mixed std::complex types
authorMatthias Maier <tamiko@43-1.org>
Mon, 7 Sep 2015 04:37:27 +0000 (23:37 -0500)
committerMatthias Maier <tamiko@43-1.org>
Mon, 7 Sep 2015 18:36:24 +0000 (13:36 -0500)
cmake/checks/check_03_compiler_bugs.cmake
include/deal.II/base/config.h.in
include/deal.II/base/tensor.h

index 17c7a0db521875eed5003bcf884d4a1d65e5ac84..a1d8d1cd3429e4cab54499f5474fba0b6a4dfe3f 100644 (file)
@@ -422,3 +422,19 @@ IF(DEAL_II_WITH_CXX11)
     )
   RESET_CMAKE_REQUIRED()
 ENDIF()
+
+
+#
+# GCC 4.8 (and possibly older) have a regression that prevents our "trick"
+# to allow multiplication of Tensor objects with std::complex<T> and
+# scalars U with different types T and U from working. In this case a
+# specialization is needed. See also base/product_type_02.cc and
+# base/product_type_03.cc
+#
+# - Matthias Maier, 2015
+#
+
+IF( CMAKE_CXX_COMPILER_ID MATCHES "GNU" AND
+    CMAKE_CXX_COMPILER_VERSION VERSION_LESS "4.9" )
+  SET(DEAL_II_GCC_COMPLEX_CONV_BUG TRUE)
+ENDIF()
index 72863f63b24505d1fad826780260a9e98968d332..cf7f55f4671edb1e95a0f884d27a8e3c8794d62a 100644 (file)
@@ -70,6 +70,7 @@
 #cmakedefine DEAL_II_BIND_NO_CONST_OP_PARENTHESES
 #cmakedefine DEAL_II_CONSTEXPR_BUG
 #cmakedefine DEAL_II_ICC_SFINAE_BUG
+#cmakedefine DEAL_II_GCC_COMPLEX_CONV_BUG
 
 
 /***********************************************************************
index a1e3d6eafe2a014867cd67c70e5f185244dcba92..28100f3110fa3f53c6532ed96896190baca6a5b4 100644 (file)
@@ -1363,6 +1363,22 @@ operator * (const Tensor<rank,dim,Number> &t,
 }
 
 
+#ifdef DEAL_II_GCC_COMPLEX_CONV_BUG
+template <int dim, typename Number, typename OtherNumber>
+inline
+Tensor<1,dim,typename ProductType<Number, typename EnableIfScalar<OtherNumber>::type>::type>
+operator * (const Tensor<1,dim,Number> &t,
+            const OtherNumber           factor)
+{
+  typedef typename ProductType<Number,OtherNumber>::type product_type;
+  Tensor<1,dim,product_type> tt;
+  for (unsigned int d=0; d<dim; ++d)
+    tt[d] = product_type(t[d]) * product_type(factor);
+  return tt;
+}
+#endif
+
+
 /**
  * Multiplication of a tensor of general rank with a scalar number from the
  * left. See the discussion with the operator with switched arguments for more

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.