From f2be14e060cf18309ef7c1cb9cec1f2a15fef806 Mon Sep 17 00:00:00 2001
From: Wolfgang Bangerth <bangerth@colostate.edu>
Date: Mon, 20 May 2024 13:58:15 -0600
Subject: [PATCH] Add one more forgotten simplification.

---
 include/deal.II/fe/fe_tools.templates.h | 28 ++++++++++++-------------
 1 file changed, 14 insertions(+), 14 deletions(-)

diff --git a/include/deal.II/fe/fe_tools.templates.h b/include/deal.II/fe/fe_tools.templates.h
index 851bc31ae7..33d25c70ad 100644
--- a/include/deal.II/fe/fe_tools.templates.h
+++ b/include/deal.II/fe/fe_tools.templates.h
@@ -223,20 +223,20 @@ namespace FETools
                          const FiniteElement<dim, spacedim> *fe5,
                          const unsigned int                  N5)
     {
-      std::vector<const FiniteElement<dim, spacedim> *> fes;
-      fes.push_back(fe1);
-      fes.push_back(fe2);
-      fes.push_back(fe3);
-      fes.push_back(fe4);
-      fes.push_back(fe5);
-
-      std::vector<unsigned int> mult;
-      mult.push_back(N1);
-      mult.push_back(N2);
-      mult.push_back(N3);
-      mult.push_back(N4);
-      mult.push_back(N5);
-      return multiply_dof_numbers(fes, mult);
+      std::vector<const FiniteElement<dim, spacedim> *> fe_list = {
+        fe1, fe2, fe3, fe4, fe5};
+      std::vector<unsigned int> multiplicities = {N1, N2, N3, N4, N5};
+
+      // This function is occasionally called with nullptr values for the
+      // finite elements. Drop those again.
+      while ((fe_list.size() > 0) && (fe_list.back() == nullptr))
+        {
+          Assert(multiplicities.back() == 0, ExcInternalError());
+          fe_list.pop_back();
+          multiplicities.pop_back();
+        }
+
+      return multiply_dof_numbers(fe_list, multiplicities);
     }
 
 
-- 
2.39.5