From: David Wells Date: Sat, 18 Aug 2018 23:39:35 +0000 (-0400) Subject: Fix some sign comparison warnings. X-Git-Tag: v9.1.0-rc1~805^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=08e7a52c9bfee3514be1b957602048ee985273fe;p=dealii.git Fix some sign comparison warnings. --- diff --git a/include/deal.II/base/table.h b/include/deal.II/base/table.h index 8e07b8eb27..bf0ad0a00b 100644 --- a/include/deal.II/base/table.h +++ b/include/deal.II/base/table.h @@ -1629,6 +1629,15 @@ namespace TransposeTableIterators */ std::ptrdiff_t linear_index; + /** + * Check that linear_index corresponds to an entry that is + * actually stored by the Table (i.e., assert that + * linear_index is nonnegative and less than + * container->size()). + */ + void + assert_valid_linear_index() const; + /** * Make the const version a friend for copying. */ @@ -2644,7 +2653,8 @@ namespace TransposeTableIterators : container(table) , linear_index(index) { - Assert(0 <= linear_index && linear_index < container->values.size() + 1, + Assert(0 <= linear_index && + std::size_t(linear_index) < container->values.size() + 1, ExcMessage("The current iterator points outside of the table and is " "not the end iterator.")); } @@ -2655,8 +2665,7 @@ namespace TransposeTableIterators inline const T & AccessorBase::value() const { - Assert(0 <= linear_index && linear_index < container->values.size(), - ExcMessage("The current iterator points outside of the table.")); + assert_valid_linear_index(); return this->container->values[linear_index]; } @@ -2666,12 +2675,8 @@ namespace TransposeTableIterators inline typename AccessorBase::size_type AccessorBase::AccessorBase::row() const { - Assert(!container->empty(), - ExcMessage("An empty table has no rows or columns.")); - const auto row_n = linear_index % container->n_rows(); - Assert(0 <= row_n && row_n < container->n_rows(), - ExcMessage("The current iterator points outside the table.")); - return row_n; + assert_valid_linear_index(); + return linear_index % container->n_rows(); } @@ -2680,22 +2685,38 @@ namespace TransposeTableIterators inline typename AccessorBase::size_type AccessorBase::AccessorBase::column() const { + assert_valid_linear_index(); + return linear_index / container->n_rows(); + } + + + + template + inline void + AccessorBase::AccessorBase::assert_valid_linear_index() const + { +# ifdef DEBUG // avoid unused variable warnings by guarding everything Assert(!container->empty(), ExcMessage("An empty table has no rows or columns.")); + Assert(0 <= linear_index && + std::size_t(linear_index) < container->values.size(), + ExcMessage("The current iterator points outside of the table.")); const auto column_n = linear_index / container->n_rows(); - Assert(0 <= column_n && column_n < container->n_cols(), + Assert(0 <= column_n && std::size_t(column_n) < container->n_cols(), ExcMessage("The current iterator points outside the table.")); - return column_n; + const auto row_n = linear_index % container->n_rows(); + Assert(0 <= row_n && std::size_t(row_n) < container->n_rows(), + ExcMessage("The current iterator points outside the table.")); +# endif } + template inline const Accessor & Accessor::operator=(const T &t) const { - Assert(0 <= this->linear_index && - this->linear_index < this->container->values.size(), - ExcMessage("The current iterator points outside of the table.")); + this->assert_valid_linear_index(); this->container->values[this->linear_index] = t; return *this; } @@ -2706,9 +2727,7 @@ namespace TransposeTableIterators inline const Accessor & Accessor::operator=(T &&t) const { - Assert(0 <= this->linear_index && - this->linear_index < this->container->values.size(), - ExcMessage("The current iterator points outside of the table.")); + this->assert_valid_linear_index(); this->container->values[this->linear_index] = t; return *this; } @@ -2719,9 +2738,7 @@ namespace TransposeTableIterators inline T & Accessor::value() const { - Assert(0 <= this->linear_index && - this->linear_index < this->container->values.size(), - ExcMessage("The current iterator points outside of the table.")); + this->assert_valid_linear_index(); return this->container->values[this->linear_index]; }