From: Daniel Arndt Date: Tue, 2 Jan 2018 18:49:58 +0000 (+0100) Subject: Avoid compiler warning regarding writing X-Git-Tag: v9.0.0-rc1~606^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e1f20446355526a53cc3f46aeff55c1b103f7174;p=dealii.git Avoid compiler warning regarding writing beyond the end of an array --- diff --git a/include/deal.II/base/point.h b/include/deal.II/base/point.h index 2b63fd5c4d..64bfa589af 100644 --- a/include/deal.II/base/point.h +++ b/include/deal.II/base/point.h @@ -318,19 +318,12 @@ Point::Point (const Number x, "that takes two arguments. Point 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::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; }