Intel® oneAPI Threading Building Blocks
Ask questions and share information about adding parallelism to your applications when using this threading library.
2422 Discussions

Warnings due to missing (size_t) cast on literal in bit-shift ops inside class ets_base.


Hi! In TBB 4.4 U3, the file enumerable_thread_specific.h contains a class "ets_base" with an inner struct "ets_base::array".

This ets_base::array struct has a method size() implemented using a bit-shift operation:

size_t size() const { return (size_t)1 << lg_size; }

The (size_t) cast on the literal number 1 ensures that the bit-shift operation is adapted according to 32-bit and 64-bit builds. (The bit-shift operator uses the type of the left operand.)

However, in the methods ets_base::allocate() and ets_base::free() a similar bit-shift appears but without the (size_t) cast on the literal number 1. When compiling in VS2015 Update 2 RTM (just released) these two methods give the following warning:

Warning C4334: '<<' : result of 32-bit shift implicitly converted to 64 bits (was 64-bit shift intended?)

(See for more info on this warning.)

This warning can easily be removed by simply adding the same (size_t) cast as in the ets_base::array::size() method.

Thanks, Göran Wallgren.

0 Kudos
1 Reply

Forgot to mention that the warning appears in 64-bit build...