From c341a94450d4ad1138005abdcf015197c2d514c6 Mon Sep 17 00:00:00 2001 From: Daniel Arndt Date: Wed, 18 Sep 2019 20:07:14 -0600 Subject: [PATCH] Avoid dangling pointer in initializer_list --- include/deal.II/base/patterns.h | 2 +- include/deal.II/hp/fe_collection.h | 3 ++- include/deal.II/hp/q_collection.h | 3 ++- tests/mpi/hp_unify_dof_indices_07.cc | 4 +--- tests/vector_tools/integrate_difference_04_hp.cc | 3 +-- 5 files changed, 7 insertions(+), 8 deletions(-) diff --git a/include/deal.II/base/patterns.h b/include/deal.II/base/patterns.h index e369cacde0..413781ec15 100644 --- a/include/deal.II/base/patterns.h +++ b/include/deal.II/base/patterns.h @@ -1439,7 +1439,7 @@ namespace Patterns "are derived from PatternBase"); static_assert(sizeof...(ps) > 0, "The number of PatternTypes must be greater than zero!"); - auto pattern_pointers = {(static_cast(&ps))...}; + const auto &pattern_pointers = {(static_cast(&ps))...}; for (const auto p : pattern_pointers) patterns.push_back(p->clone()); } diff --git a/include/deal.II/hp/fe_collection.h b/include/deal.II/hp/fe_collection.h index a422679dd4..613d9392ee 100644 --- a/include/deal.II/hp/fe_collection.h +++ b/include/deal.II/hp/fe_collection.h @@ -834,7 +834,8 @@ namespace hp // loop over all of the given arguments and add the finite elements to // this collection. Inlining the definition of fe_pointers causes internal // compiler errors on GCC 7.1.1 so we define it separately: - const auto fe_pointers = {&fes...}; + const auto &fe_pointers = + std::initializer_list *>{&fes...}; for (const auto p : fe_pointers) push_back(*p); } diff --git a/include/deal.II/hp/q_collection.h b/include/deal.II/hp/q_collection.h index 1bba0eff84..ecdc5d8384 100644 --- a/include/deal.II/hp/q_collection.h +++ b/include/deal.II/hp/q_collection.h @@ -156,7 +156,8 @@ namespace hp // loop over all of the given arguments and add the quadrature objects to // this collection. Inlining the definition of q_pointers causes internal // compiler errors on GCC 7.1.1 so we define it separately: - const auto q_pointers = {&quadrature_objects...}; + const auto &q_pointers = + std::initializer_list *>{&quadrature_objects...}; for (const auto p : q_pointers) push_back(*p); } diff --git a/tests/mpi/hp_unify_dof_indices_07.cc b/tests/mpi/hp_unify_dof_indices_07.cc index 8bd1d7b6fd..4991bf1781 100644 --- a/tests/mpi/hp_unify_dof_indices_07.cc +++ b/tests/mpi/hp_unify_dof_indices_07.cc @@ -70,9 +70,7 @@ test() Assert(triangulation.n_global_active_cells() == 2, ExcInternalError()); Assert(triangulation.n_active_cells() == 2, ExcInternalError()); - hp::FECollection fe; - fe.push_back(FE_Q(2)); - fe.push_back(FE_Q(2)); + hp::FECollection fe(FE_Q(2), FE_Q(2)); hp::DoFHandler dof_handler(triangulation); if (dof_handler.begin_active()->is_locally_owned()) diff --git a/tests/vector_tools/integrate_difference_04_hp.cc b/tests/vector_tools/integrate_difference_04_hp.cc index 531c56c5be..db4aecb441 100644 --- a/tests/vector_tools/integrate_difference_04_hp.cc +++ b/tests/vector_tools/integrate_difference_04_hp.cc @@ -101,8 +101,7 @@ test(VectorTools::NormType norm, double value, double exp = 2.0) solution = interpolated; Vector cellwise_errors(tria.n_active_cells()); - hp::QCollection quadrature; - quadrature.push_back(QIterated(QTrapez<1>(), 5)); + hp::QCollection quadrature(QIterated(QTrapez<1>(), 5)); const dealii::Function *w = nullptr; VectorTools::integrate_difference(dofh, -- 2.39.5