warning C4309: 'specialization': truncation of constant value

Started by
2 comments, last by Khatharr 7 years, 5 months ago

Here, I'm calling uint32_t version of Packer::pack, but I'm getting this warning.

Could someone help me out? Thanks!


Packer packer;
packer.pack<0, 127>(7u); //no warning
packer.pack<0, 128>(7u); //warning

class Packer
{
public:
Packer();


const void * getData() const;
std::size_t getDataSize() const;
void pack(bool data);

template <std::int8_t min = (std::numeric_limits<std::int8_t>::min)(), std::int8_t max = (std::numeric_limits<std::int8_t>::max)()>
void pack(std::int8_t data);

template <std::uint8_t min = (std::numeric_limits<std::uint8_t>::min)(), std::uint8_t max = (std::numeric_limits<std::uint8_t>::max)()>
void pack(std::uint8_t data);

template <std::int16_t min = (std::numeric_limits<std::int16_t>::min)(), std::int16_t max = (std::numeric_limits<std::int16_t>::max)()>
void pack(std::int16_t data);

template <std::uint16_t min = (std::numeric_limits<std::uint16_t>::min)(), std::uint16_t max = (std::numeric_limits<std::uint16_t>::max)()>
void pack(std::uint16_t data);

template <std::int32_t min = (std::numeric_limits<std::int32_t>::min)(), std::int32_t max = (std::numeric_limits<std::int32_t>::max)()>
void pack(std::int32_t data);

template <std::uint32_t min = (std::numeric_limits<std::uint32_t>::min)(), std::uint32_t max = (std::numeric_limits<std::uint32_t>::max)()>
void pack(std::uint32_t data);

...

An invisible text.
Advertisement

Try packer.pack<0u, 128u>(7u);

Thanks, that works.

But I don't understand why I don't get a warning with packer.pack<0, 127>(7u)?

An invisible text.

Because 127 will fit in a signed char. Templates are a bit manky around type conversions.

void hurrrrrrrr() {__asm sub [ebp+4],5;}

There are ten kinds of people in this world: those who understand binary and those who don't.

This topic is closed to new replies.

Advertisement