From e1f20446355526a53cc3f46aeff55c1b103f7174 Mon Sep 17 00:00:00 2001 From: Daniel Arndt Date: Tue, 2 Jan 2018 19:49:58 +0100 Subject: [PATCH] Avoid compiler warning regarding writing beyond the end of an array --- include/deal.II/base/point.h | 37 ++++++++++++------------------------ 1 file changed, 12 insertions(+), 25 deletions(-) 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; } -- 2.39.5