]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Work around a GCC-12 warning about array accesses. 14029/head
authorDavid Wells <drwells@email.unc.edu>
Tue, 21 Jun 2022 13:41:19 +0000 (09:41 -0400)
committerDavid Wells <drwells@email.unc.edu>
Tue, 21 Jun 2022 14:21:54 +0000 (10:21 -0400)
This only occurs at higher optimization levels with -Warray-bounds.

include/deal.II/grid/reference_cell.h

index e27120347dca56c907fff81d417df1075ba002f4..8d30f42b49f4ec622f75160029ea1099562058d7 100644 (file)
@@ -1311,6 +1311,9 @@ ReferenceCell::standard_vertex_to_face_and_vertex_index(
   const unsigned int vertex) const
 {
   AssertIndexRange(vertex, n_vertices());
+  // Work around a GCC warning at higher optimization levels by making all of
+  // these tables the same size
+  constexpr unsigned int X = numbers::invalid_unsigned_int;
 
   if (*this == ReferenceCells::Vertex)
     {
@@ -1322,8 +1325,8 @@ ReferenceCell::standard_vertex_to_face_and_vertex_index(
     }
   else if (*this == ReferenceCells::Triangle)
     {
-      static const ndarray<unsigned int, 3, 2> table = {
-        {{{0, 0}}, {{0, 1}}, {{1, 1}}}};
+      static const ndarray<unsigned int, 6, 2> table = {
+        {{{0, 0}}, {{0, 1}}, {{1, 1}}, {{X, X}}, {{X, X}}, {{X, X}}}};
 
       return table[vertex];
     }
@@ -1333,15 +1336,15 @@ ReferenceCell::standard_vertex_to_face_and_vertex_index(
     }
   else if (*this == ReferenceCells::Tetrahedron)
     {
-      static const ndarray<unsigned int, 4, 2> table = {
-        {{{0, 0}}, {{0, 1}}, {{0, 2}}, {{1, 2}}}};
+      static const ndarray<unsigned int, 6, 2> table = {
+        {{{0, 0}}, {{0, 1}}, {{0, 2}}, {{1, 2}}, {{X, X}}, {{X, X}}}};
 
       return table[vertex];
     }
   else if (*this == ReferenceCells::Pyramid)
     {
-      static const ndarray<unsigned int, 5, 2> table = {
-        {{{0, 0}}, {{0, 1}}, {{0, 2}}, {{0, 3}}, {{1, 2}}}};
+      static const ndarray<unsigned int, 6, 2> table = {
+        {{{0, 0}}, {{0, 1}}, {{0, 2}}, {{0, 3}}, {{1, 2}}, {{X, X}}}};
 
       return table[vertex];
     }

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.