]> https://gitweb.dealii.org/ - dealii.git/commitdiff
lac/constraints_move: Fix undefined behavior 10519/head
authorMatthias Maier <tamiko@43-1.org>
Fri, 12 Jun 2020 05:50:50 +0000 (00:50 -0500)
committerMatthias Maier <tamiko@43-1.org>
Fri, 12 Jun 2020 05:54:54 +0000 (00:54 -0500)
It is undefined behavior to access an object that has been moved. It is
also not possible to "move back" an object.

In this particular case with the recent changes to ThreadLocalStorage
and AffineConstraints we run into an exception:

constraints_move.debug: ../nptl/pthread_mutex_lock.c:117: __pthread_mutex_lock: Assertion `mutex->__data.__owner == 0' failed.

(The move operation destroys the mutex and accessing it afterwards
when we try to move back results in a crash.)

tests/lac/constraints_move.cc
tests/lac/constraints_move.output

index 9e62b6544a2842ae525408c6101435847f581deb..8ff9f44cf22a0c46a18a16c72303cdf6d987f96a 100644 (file)
@@ -39,11 +39,6 @@ main()
 
   AffineConstraints<double> cm(std::move(constraints));
   cm.print(deallog.get_file_stream());
-  deallog << constraints.n_constraints() << std::endl << std::endl;
-
-  constraints = std::move(cm);
-  constraints.print(deallog.get_file_stream());
-  deallog << cm.n_constraints() << std::endl;
 
   deallog << "OK" << std::endl;
 }
index d44670c0ecbd4d64d4c413a6181e6e987c7f4286..2a4ad2699a3fe77052a08bf3278b656273b676a0 100644 (file)
@@ -1,27 +1,17 @@
 
-    1 = 0.0
-    2 = 1.0
-    3 = 2.0
-    5 = 3.0
-    8 = 4.0
-    13 = 5.0
-    21 = 6.0
+    1 = 0
+    2 = 1.00000
+    3 = 2.00000
+    5 = 3.00000
+    8 = 4.00000
+    13 = 5.00000
+    21 = 6.00000
 DEAL::
-    1 = 0.0
-    2 = 1.0
-    3 = 2.0
-    5 = 3.0
-    8 = 4.0
-    13 = 5.0
-    21 = 6.0
-DEAL::0
-DEAL::
-    1 = 0.0
-    2 = 1.0
-    3 = 2.0
-    5 = 3.0
-    8 = 4.0
-    13 = 5.0
-    21 = 6.0
-DEAL::0
+    1 = 0
+    2 = 1.00000
+    3 = 2.00000
+    5 = 3.00000
+    8 = 4.00000
+    13 = 5.00000
+    21 = 6.00000
 DEAL::OK

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.