]> https://gitweb.dealii.org/ - dealii.git/commitdiff
base/polynomials_bdm.cc: avoid a compiler warning with gcc-12 13925/head
authorMatthias Maier <tamiko@43-1.org>
Tue, 7 Jun 2022 22:46:14 +0000 (17:46 -0500)
committerMatthias Maier <tamiko@43-1.org>
Tue, 7 Jun 2022 22:46:14 +0000 (17:46 -0500)
gcc-12 in release mode will inline the evaluate function into some
methods of the FE_BDM class. It then rightfully complains that the (now
modified) else branch will write out of bounds.

Despite the fact that we instantiate this polynomials class and the
related FE class for 1d this code has never worked. Thus, fail
prominently with an error message.

source/base/polynomials_bdm.cc

index 0fc44c86b09263cc2faa3a71610997da938b723a..e4bd9dadee75f073b96e9951849462798bd7beb2 100644 (file)
@@ -122,7 +122,15 @@ PolynomialsBDM<dim>::evaluate(
   std::vector<std::vector<double>> monovali(dim, std::vector<double>(4));
   std::vector<std::vector<double>> monovalk(dim, std::vector<double>(4));
 
-  if (dim == 2)
+  if (dim == 1)
+    {
+      // Despite the fact that we are instantiating this class for 1, 2 and
+      // 3 space dimensions we only support dimension 2 and 3.
+      Assert(false,
+             dealii::ExcMessage("PolynomialsBDF::evaluate is only "
+                                "available for dim == 2, or dim == 3"));
+    }
+  else if (dim == 2)
     {
       for (unsigned int d = 0; d < dim; ++d)
         monomials[0].value(unit_point(d), monovali[d]);
@@ -164,7 +172,7 @@ PolynomialsBDM<dim>::evaluate(
           grad_grads[start + 1][1][1][1] = -monovali[1][2];
         }
     }
-  else // dim == 3
+  else if (dim == 3)
     {
       // The number of curls in each component. Note that the table in
       // BrezziFortin91 has a typo, but the text has the right basis
@@ -182,6 +190,7 @@ PolynomialsBDM<dim>::evaluate(
               monomials[this->degree() - 1 - i].value(unit_point(d),
                                                       monovalk[d]);
             }
+
           if (values.size() != 0)
             {
               // x p'(y) q(z)
@@ -205,6 +214,7 @@ PolynomialsBDM<dim>::evaluate(
               values[start + 2][0] = -monovali[0][0] * monovalk[1][0];
               values[start + 2][1] = 0.;
             }
+
           if (grads.size() != 0)
             {
               grads[start][0][0] = monovali[1][1] * monovalk[2][0];
@@ -243,6 +253,7 @@ PolynomialsBDM<dim>::evaluate(
               grads[start + 2][1][0] = 0.;
               grads[start + 2][1][1] = 0.;
             }
+
           if (grad_grads.size() != 0)
             {
               grad_grads[start][0][0][0] = 0.;

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.