If I use the compiler option -Wfloat-equal with GCC or Clang, equality comparisons of float/double values cause a warning. However, when comparing containers (like std::vector or std::tuple) of float or double values, no such warning is raised.
Example code (also at https://godbolt.org/z/YP8v8hTs3):
#include <tuple>
#include <vector>
#include <assert.h>
int main() {
double d = 1.2;
std::tuple<double, double> t_d{1.2, 3.14};
std::tuple<double, double> t_d_2{1.2, 3.14};
std::vector<double> v_d{1.2, 3.14};
std::vector<double> v_d_2{1.2, 3.14};
// this causes a warning, like "warning: comparing floating-point with '==' or '!=' is unsafe [-Wfloat-equal]":
assert(d == 1.2);
// but why no warning from -Wfloat-equal here?
assert(t_d == t_d_2);
// no warning here either:
assert(v_d == v_d_2);
// all of these cause warnings as expected:
assert(std::get<0>(t_d) == 1.2);
assert(std::get<0>(t_d) == std::get<0>(t_d_2));
assert(v_d[0] == 1.2);
assert(v_d[0] == v_d_2[0]);
return 0;
}
Why are the warnings omitted for these container comparisons? And more importantly, what can I do to actually get these warnings as well?