Forbid integer conversion with precision loss
问题 How to prevent such code from compiling? #include <vector> #include <limits> #include <iostream> #include <cstdint> int main() { std::vector<int16_t> v; v.emplace_back(std::numeric_limits<uint64_t>::max()); std::cout << v.back() << std::endl; return 0; } g++ and clang with -std=c++14 -Wall -Wextra -Werror -pedantic -Wold-style-cast -Wconversion -Wsign-conversion don't even warn about it. The example also compiles without warnings with std::vector<uint16_t> 回答1: Add -Wsystem-headers to the