https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96742

--- Comment #2 from William Throwe <wtt6 at cornell dot edu> ---
It was decided in bug 11856 that it was a bug to warn about comparisons when a
choice for a type template parameter made them always false, so it seems like
it should also be a bug to warn if a non-type template parameter makes them
always false.

More practically, the warning is basically unactionable when template arguments
are involved.  Here's a slightly more complex example:
---
template <typename T, size_t N>
T f(const std::array<T, N>& x) {
  T ret = 0;
  for (size_t i = 0; i < N; ++i) {
    ret += i * x[i];
  }
  return ret;
}
---
This warns if passed an array of length 0 because the for-loop condition is
always false.  Any change I can make to fix it seems to make the code worse.  I
could replace "i < N" with "i + 1 < N + 1", but that certainly doesn't make the
code clearer (and in similar cases could lead to weird overflow bugs).  I can't
partially specialize the function, because that's not allowed.  I could write
an implementation struct and specialize that, but that seems like massive
overkill when the generic function works fine.

Reply via email to