Let's take the following simple example:
#include <vector>
#include <cstdint>
using ::std::vector;
using ::std::uint64_t;
using ::std::uint32_t;
int main(int argc, char *argv[])
{
vector<uint64_t> v;
uint32_t i = 1;
v.push_back(i);
return 0;
}
When I compile it with:
g++ -std=c++11 -Wall -Wconversion -Wpedantic a.cpp
I don't get any conversion error. However, I want gcc to warn me because the types uint64_t
and uint32_t
don't perfectly match. I undertand that a uint32_t
fits into a uint64_t
, but it still some code smell to me. (I would like gcc to force me to cast it)
Is there a way to have gcc warn about that?
There is nothing wrong with that conversion because the a
uint32_t
being converted to auint64_t
will not alter the value: https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wconversion-499There won't be a compiler flag for
j = i;
because there is nothing wrong with it, the "smell" is just your preference