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

--- Comment #17 from Jonathan Wakely <redi at gcc dot gnu.org> ---
And Bug 87614 is a simpler form of Ian's original example in comment 0:

#include <vector>

int main() {
    std::vector<unsigned short> a;
    a.emplace_back(70000);
}

With -Wsystem-header -Wconversion:

[...]
87614.cc:5:25:   required from here
/home/jwakely/gcc/9/include/c++/9.0.1/ext/new_allocator.h:147:4: warning:
conversion from 'int' to 'short unsigned int' may change value [-Wconversion]
  147 |  { ::new((void *)__p) _Up(std::forward<_Args>(__args)...); }
      |    ^

This error comes from the user's code, the fact the actual conversion happens
deep inside libstdc++ rather than at the call site is only because the function
templates preserves the original type all the way down. But the error is in the
user's code, not in the libstdc++ code which is just doing what it was told to
by the user.

The better GCC gets at detecting such problems and warning about them, the
bigger a problem it becomes that using templates from the C++ standard library
suppresses all GCC's useful warnings.

Reply via email to