]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Bugfix: Disallow templated constructor/copy assignment for derived classes 1557/head
authorMatthias Maier <tamiko@43-1.org>
Tue, 8 Sep 2015 16:04:55 +0000 (11:04 -0500)
committerMatthias Maier <tamiko@43-1.org>
Tue, 8 Sep 2015 16:04:55 +0000 (11:04 -0500)
include/deal.II/lac/linear_operator.h
tests/lac/block_linear_operator_01.cc

index bc09bbf58d4e9526d90567cd0a6c4ae424b5f4fc..2b4808d403f15af0795e783bd4da41b737b440c4 100644 (file)
@@ -22,8 +22,9 @@
 
 #ifdef DEAL_II_WITH_CXX11
 
-#include <functional>
 #include <array>
+#include <functional>
+#include <type_traits>
 
 DEAL_II_NAMESPACE_OPEN
 
@@ -169,11 +170,12 @@ public:
   LinearOperator (const LinearOperator<Range, Domain> &) = default;
 
   /**
-   * Templated copy constructor that creates a LinearOperator object from an
-   * object @p op for which the conversion function
+   * Templated copy constructor that creates a LinearOperator object from
+   * an object @p op for which the conversion function
    * <code>linear_operator</code> is defined.
    */
-  template<typename Op>
+  template<typename Op,
+           typename = typename std::enable_if<!std::is_base_of<LinearOperator<Range, Domain>, Op>::value>::type>
   LinearOperator (const Op &op)
   {
     *this = linear_operator<Range, Domain, Op>(op);
@@ -189,7 +191,8 @@ public:
    * Templated copy assignment operator for an object @p op for which the
    * conversion function <code>linear_operator</code> is defined.
    */
-  template <typename Op>
+  template <typename Op,
+            typename = typename std::enable_if<!std::is_base_of<LinearOperator<Range, Domain>, Op>::value>::type>
   LinearOperator<Range, Domain> &operator=(const Op &op)
   {
     *this = linear_operator<Range, Domain, Op>(op);
index 1d4d6149a4e406734bdeabe5f136a17d066c3766..5c4e033f2c5b09bb6a4f66e33cab3038266094e6 100644 (file)
@@ -112,6 +112,13 @@ int main()
                                                       };
   auto op_b = block_operator<2, 2, BlockVector<double>>(temp);
 
+  {
+    // also test copy and reference assignment to a LinearOperator
+    LinearOperator<BlockVector<double>> &op_x1 = op_b;
+    LinearOperator<BlockVector<double>>  op_x2 = op_b;
+    LinearOperator<BlockVector<double>> op_x3(op_b);
+  }
+
   // vmult:
 
   BlockVector<double> u;

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.