]> https://gitweb.dealii.org/ - dealii.git/commitdiff
FESystem: do not abuse Subscriptor* as a fancy void* 15564/head
authorMatthias Maier <tamiko@43-1.org>
Sat, 1 Jul 2023 14:44:58 +0000 (09:44 -0500)
committerMatthias Maier <tamiko@43-1.org>
Sat, 1 Jul 2023 19:16:14 +0000 (14:16 -0500)
Instead use dynamic_cast to check for cast compatibility at runtime.
Interestengly, we already did in the debug Assert to check that
everything is in order.

source/fe/fe_system.cc

index 1d2102928cbf02e6a61a92e202aff6f4b668bca8..d7a6627c379512dba1e15ac6e0173c6c5f141947 100644 (file)
@@ -1431,39 +1431,29 @@ FESystem<dim, spacedim>::compute_fill(
         // static cast through the common base class:
         if (face_no == invalid_face_number)
           {
-            const Subscriptor *quadrature_base_pointer = &quadrature;
-            Assert(dynamic_cast<const Quadrature<dim> *>(
-                     quadrature_base_pointer) != nullptr,
-                   ExcInternalError());
-
             cell_quadrature =
-              static_cast<const Quadrature<dim> *>(quadrature_base_pointer);
+              dynamic_cast<const Quadrature<dim> *>(&quadrature);
+            Assert(cell_quadrature != nullptr, ExcInternalError());
             n_q_points = cell_quadrature->size();
           }
         else if (sub_no == invalid_face_number)
           {
-            const Subscriptor *quadrature_base_pointer = &quadrature;
-            Assert(dynamic_cast<const hp::QCollection<dim - 1> *>(
-                     quadrature_base_pointer) != nullptr,
-                   ExcInternalError());
-
             // If we don't have wedges or pyramids then there should only be one
             // quadrature rule here
-            face_quadrature = static_cast<const hp::QCollection<dim - 1> *>(
-              quadrature_base_pointer);
+            face_quadrature =
+              dynamic_cast<const hp::QCollection<dim - 1> *>(&quadrature);
+            Assert(face_quadrature != nullptr, ExcInternalError());
+
             n_q_points =
               (*face_quadrature)[face_quadrature->size() == 1 ? 0 : face_no]
                 .size();
           }
         else
           {
-            const Subscriptor *quadrature_base_pointer = &quadrature;
-            Assert(dynamic_cast<const Quadrature<dim - 1> *>(
-                     quadrature_base_pointer) != nullptr,
-                   ExcInternalError());
-
             sub_face_quadrature =
-              static_cast<const Quadrature<dim - 1> *>(quadrature_base_pointer);
+              dynamic_cast<const Quadrature<dim - 1> *>(&quadrature);
+            Assert(sub_face_quadrature != nullptr, ExcInternalError());
+
             n_q_points = sub_face_quadrature->size();
           }
         Assert(n_q_points != numbers::invalid_unsigned_int, ExcInternalError());

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.