From: Wolfgang Bangerth Date: Sat, 26 Nov 2016 05:17:56 +0000 (-0700) Subject: Do not instantiate invalid classes. X-Git-Tag: v8.5.0-rc1~360^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9386b1e30c902adefda56f85e9bd9af86687d8e8;p=dealii.git Do not instantiate invalid classes. We have numerous places where we do something of the sort template void foo (const Triangulation &triangulation) { if (dim == 3) { typename Triangulation<3,spacedim>::cell_iterator cell = triangulation.begin(); ... Since we only get into this piece of code if dim==3, there is nothing wrong with this: if dim==3, then spacedim>=3. On the other hand, the compiler will still instantiate Triangulation<3,spacedim> even if dim==spacedim==1. This patch works around this by replacing the type by Triangulation<3,max(3,spacedim)> which for all of the cases in question leads to the exact same type, but avoids instantiating invalid types. --- diff --git a/source/grid/tria_accessor.cc b/source/grid/tria_accessor.cc index cfcc932819..7765c5d7c5 100644 --- a/source/grid/tria_accessor.cc +++ b/source/grid/tria_accessor.cc @@ -1773,7 +1773,7 @@ CellAccessor::neighbor_of_coarser_neighbor (const unsigned int ne case 2: { const int this_face_index=face_index(neighbor); - const TriaIterator > neighbor_cell = this->neighbor(neighbor); + const TriaIterator > neighbor_cell = this->neighbor(neighbor); // usually, on regular patches of // the grid, this cell is just on @@ -1791,7 +1791,7 @@ CellAccessor::neighbor_of_coarser_neighbor (const unsigned int ne const unsigned int face_no_guess = GeometryInfo<2>::opposite_face[neighbor]; - const TriaIterator > face_guess + const TriaIterator > face_guess =neighbor_cell->face(face_no_guess); if (face_guess->has_children()) @@ -1807,7 +1807,7 @@ CellAccessor::neighbor_of_coarser_neighbor (const unsigned int ne { if (face_no!=face_no_guess) { - const TriaIterator > face + const TriaIterator > face =neighbor_cell->face(face_no); if (face->has_children()) for (unsigned int subface_no=0; subface_non_children(); ++subface_no) @@ -1827,7 +1827,7 @@ CellAccessor::neighbor_of_coarser_neighbor (const unsigned int ne case 3: { const int this_face_index=face_index(neighbor); - const TriaIterator > + const TriaIterator > neighbor_cell = this->neighbor(neighbor); // usually, on regular patches of the grid, this cell is just on the @@ -1839,7 +1839,7 @@ CellAccessor::neighbor_of_coarser_neighbor (const unsigned int ne const unsigned int face_no_guess = GeometryInfo<3>::opposite_face[neighbor]; - const TriaIterator > face_guess + const TriaIterator > face_guess =neighbor_cell->face(face_no_guess); if (face_guess->has_children()) @@ -1867,7 +1867,7 @@ CellAccessor::neighbor_of_coarser_neighbor (const unsigned int ne if (face_no==face_no_guess) continue; - const TriaIterator > face + const TriaIterator > face =neighbor_cell->face(face_no); if (!face->has_children()) @@ -2347,15 +2347,18 @@ neighbor_child_on_subface (const unsigned int face, // | | 1 | | 0 | | | 0 | | 0 | 1 | // *---*---* *---*---* *-------* *---*---* - const typename Triangulation<3,spacedim>::face_iterator + // in the following line, we know that if we got here that we + // have spacedim>=3. avoid instantiating invalid classes + // otherwise, even though we know that it is in dead code + const typename Triangulation<3,(spacedim<3 ? 3 : spacedim)>::face_iterator mother_face = this->face(face); const unsigned int total_children=mother_face->number_of_children(); Assert (subface::max_children_per_face, ExcInternalError()); unsigned int neighbor_neighbor; - TriaIterator > neighbor_child; - const TriaIterator > neighbor + TriaIterator > neighbor_child; + const TriaIterator > neighbor = this->neighbor(face); @@ -2558,9 +2561,13 @@ neighbor_child_on_subface (const unsigned int face, 0)); #ifdef DEBUG - // check, whether the face neighbor_child - // matches the requested subface - typename Triangulation<3,spacedim>::face_iterator requested; + // check, whether the face neighbor_child matches the requested + // subface. + // + // in the following line, we know that if we got here that we + // have spacedim>=3. avoid instantiating invalid classes + // otherwise, even though we know that it is in dead code + typename Triangulation<3,(spacedim<3 ? 3 : spacedim)>::face_iterator requested; switch (this->subface_case(face)) { case internal::SubfaceCase<3>::case_x: