]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Check own subscriptions when assigning in Subscriptor 6333/head
authorDaniel Arndt <daniel.arndt@iwr.uni-heidelberg.de>
Wed, 25 Apr 2018 16:51:28 +0000 (18:51 +0200)
committerDaniel Arndt <daniel.arndt@iwr.uni-heidelberg.de>
Wed, 25 Apr 2018 17:34:26 +0000 (19:34 +0200)
source/base/subscriptor.cc
tests/base/assign_subscriptor.cc [new file with mode: 0644]
tests/base/assign_subscriptor.output [new file with mode: 0644]

index 07aad6d59a8cbcd6633cc67f21a958a462bee146..631d5e66650fd47dfbae292b1375af2498e27123 100644 (file)
@@ -129,6 +129,7 @@ void Subscriptor::check_no_subscribers () const
 
 Subscriptor &Subscriptor::operator = (const Subscriptor &s)
 {
+  check_no_subscribers();
   object_info = s.object_info;
   return *this;
 }
@@ -137,6 +138,7 @@ Subscriptor &Subscriptor::operator = (const Subscriptor &s)
 
 Subscriptor &Subscriptor::operator = (Subscriptor &&s) noexcept
 {
+  check_no_subscribers();
   s.check_no_subscribers();
   object_info = s.object_info;
   return *this;
diff --git a/tests/base/assign_subscriptor.cc b/tests/base/assign_subscriptor.cc
new file mode 100644 (file)
index 0000000..25c89f1
--- /dev/null
@@ -0,0 +1,88 @@
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2018 by the deal.II authors
+//
+// This file is part of the deal.II library.
+//
+// The deal.II library is free software; you can use it, redistribute
+// it, and/or modify it under the terms of the GNU Lesser General
+// Public License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+// The full text of the license can be found in the file LICENSE at
+// the top level of the deal.II distribution.
+//
+// ---------------------------------------------------------------------
+
+
+
+// check that Subscriptor objects need to be empty before assigning.
+
+
+#include "../tests.h"
+#include <deal.II/base/subscriptor.h>
+#include <deal.II/base/smartpointer.h>
+#include <iostream>
+#include <vector>
+
+class Test : public Subscriptor
+{};
+
+int main()
+{
+  deal_II_exceptions::disable_abort_on_exception();
+
+  initlog();
+
+  // should work
+  {
+    Subscriptor subscriptor_1;
+    Subscriptor subscriptor_2;
+
+    SmartPointer<Subscriptor> smart (&subscriptor_1);
+
+    subscriptor_2 = subscriptor_1;
+  }
+
+  try
+    {
+      Subscriptor subscriptor_1;
+      Subscriptor subscriptor_2;
+
+      SmartPointer<Subscriptor> smart (&subscriptor_2);
+
+      subscriptor_2 = subscriptor_1;
+    }
+  catch (ExceptionBase &e)
+    {
+      deallog << e.get_exc_name() << std::endl;
+    }
+
+  try
+    {
+      Subscriptor subscriptor_1;
+      Subscriptor subscriptor_2;
+
+      SmartPointer<Subscriptor> smart (&subscriptor_1);
+
+      subscriptor_2 = std::move(subscriptor_1);
+    }
+  catch (ExceptionBase &e)
+    {
+      deallog << e.get_exc_name() << std::endl;
+    }
+
+  try
+    {
+      Subscriptor subscriptor_1;
+      Subscriptor subscriptor_2;
+
+      SmartPointer<Subscriptor> smart (&subscriptor_2);
+
+      subscriptor_2 = std::move(subscriptor_1);
+    }
+  catch (ExceptionBase &e)
+    {
+      deallog << e.get_exc_name() << std::endl;
+    }
+}
+
diff --git a/tests/base/assign_subscriptor.output b/tests/base/assign_subscriptor.output
new file mode 100644 (file)
index 0000000..e2b839e
--- /dev/null
@@ -0,0 +1,34 @@
+
+DEAL::Exception: ExcInUse (counter, object_info->name(), infostring)
+DEAL::
+--------------------------------------------------------
+An error occurred in file <subscriptor.cc> in function
+    void dealii::Subscriptor::check_no_subscribers() const
+The violated condition was: 
+    counter == 0
+Additional information: 
+    (none)
+--------------------------------------------------------
+
+DEAL::Exception: ExcInUse (counter, object_info->name(), infostring)
+DEAL::
+--------------------------------------------------------
+An error occurred in file <subscriptor.cc> in function
+    void dealii::Subscriptor::check_no_subscribers() const
+The violated condition was: 
+    counter == 0
+Additional information: 
+    (none)
+--------------------------------------------------------
+
+DEAL::Exception: ExcInUse (counter, object_info->name(), infostring)
+DEAL::
+--------------------------------------------------------
+An error occurred in file <subscriptor.cc> in function
+    void dealii::Subscriptor::check_no_subscribers() const
+The violated condition was: 
+    counter == 0
+Additional information: 
+    (none)
+--------------------------------------------------------
+

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.