]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Avoid compiler warning regarding writing 5692/head
authorDaniel Arndt <daniel.arndt@iwr.uni-heidelberg.de>
Tue, 2 Jan 2018 18:49:58 +0000 (19:49 +0100)
committerDaniel Arndt <daniel.arndt@iwr.uni-heidelberg.de>
Tue, 2 Jan 2018 22:21:26 +0000 (23:21 +0100)
beyond the end of an array

include/deal.II/base/point.h

index 2b63fd5c4dd7bc6f90d5cd9cd71145e123d0584f..64bfa589af99a4fedcbd320acd0f11ffd9ea8372 100644 (file)
@@ -318,19 +318,12 @@ Point<dim,Number>::Point (const Number x,
                       "that takes two arguments. Point<dim> objects with dim!=2 "
                       "require initialization with the constructor that takes 'dim' "
                       "arguments."));
-  // we can only get here if we pass the assertion. use the switch anyway so
-  // as to avoid compiler warnings about uninitialized elements or writing
+  // we can only get here if we pass the assertion. use the indirection anyway
+  // so as to avoid compiler warnings about uninitialized elements or writing
   // beyond the end of the 'values' array
-  switch (dim)
-    {
-    case 2:
-      this->values[0] = x;
-      this->values[1] = y;
-      break;
-
-    default:
-      ;
-    }
+  constexpr unsigned int y_index = (dim<2)?0:1;
+  this->values[0] = x;
+  this->values[y_index] = y;
 }
 
 
@@ -347,20 +340,14 @@ Point<dim,Number>::Point (const Number x,
                       "require initialization with the constructor that takes 'dim' "
                       "arguments."));
 
-  // we can only get here if we pass the assertion. use the switch anyway so
-  // as to avoid compiler warnings about uninitialized elements or writing
+  // we can only get here if we pass the assertion. use the indirection anyway
+  // so as to avoid compiler warnings about uninitialized elements or writing
   // beyond the end of the 'values' array
-  switch (dim)
-    {
-    case 3:
-      this->values[0] = x;
-      this->values[1] = y;
-      this->values[2] = z;
-      break;
-
-    default:
-      ;
-    }
+  constexpr unsigned int y_index = (dim<2)?0:1;
+  constexpr unsigned int z_index = (dim<3)?0:2;
+  this->values[0] = x;
+  this->values[y_index] = y;
+  this->values[z_index] = z;
 }
 
 

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.