Boost C++ Libraries: Ticket #13619: boost.crc fails to compile with gcc due to undefined behaviour https://svn.boost.org/trac10/ticket/13619 <p> Boost revision: 62faaa4584e16cd60cd62d5cbb0833954686e89c<br /> Following code is minimal example to reproduce error: </p> <pre class="wiki"> #include &lt;boost/crc.hpp&gt; template class boost::crc_optimal&lt;6,6,6,6,0,0&gt;; int main() {} </pre><pre class="wiki"> $ g++ -std=c++14 -pedantic-errors -I../boost/install-root/include/ -o/dev/null crc-test.cxx In file included from ../boost/install-root/include/boost/config.hpp:61:0, from ../boost/install-root/include/boost/crc.hpp:12, from crc-test.cxx:1: ../boost/install-root/include/boost/crc.hpp: In instantiation of 'const least boost::detail::mask_uint_t&lt;6ul&gt;::sig_bits': ../boost/install-root/include/boost/crc.hpp:356:9: required from 'const fast boost::detail::mask_uint_t&lt;6ul&gt;::sig_bits_fast' ../boost/install-root/include/boost/crc.hpp:915:41: required from 'boost::crc_optimal&lt;Bits, TruncPoly, InitRem, FinalXor, ReflectIn, ReflectRem&gt;::value_type boost::crc_optimal&lt;Bits, TruncPoly, InitRem, FinalXor, ReflectIn, ReflectRem&gt;::get_interim_remainder() const [with long unsigned int Bits = 6ul; typename boost::uint_t&lt;Bits&gt;::fast TruncPoly = 6u; typename boost::uint_t&lt;Bits&gt;::fast InitRem = 6u; typename boost::uint_t&lt;Bits&gt;::fast FinalXor = 6u; bool ReflectIn = false; bool ReflectRem = false; boost::crc_optimal&lt;Bits, TruncPoly, InitRem, FinalXor, ReflectIn, ReflectRem&gt;::value_type = unsigned char]' crc-test.cxx:3:23: required from here ../boost/install-root/include/boost/crc.hpp:350:69: error: left operand of shift expression '(-1 &lt;&lt; 6ul)' is negative [-fpermissive] BOOST_STATIC_CONSTANT( least, sig_bits = (~( ~(least( 0u )) &lt;&lt; Bits )) ); ~~~~~~~~~~~~~~~~~^~~~~~~~~ </pre><p> GCC produce incorrect message: there is no -Werror options or similar, as you see. Reason is initialization of static constant in declaration in class with expression that is _not_ constant because consists UB(left shift of negative value). '0u' literal is unsigned, but promouted to 'int' when 'least' is 'unsigned char'. Error is reproductable on release 1.67.0. Solution, for example, is make explicit cast of left operand to unsigned integral type. GCC information: </p> <pre class="wiki">$ g++ -v Using built-in specs. COLLECT_GCC=g++ COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/6/lto-wrapper Target: x86_64-linux-gnu Configured with: ../src/configure -v --with-pkgversion='Debian 6.3.0-18+deb9u1' --with-bugurl=file:///usr/share/doc/gcc-6/README.Bugs --enable-languages=c,ada,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-6 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --enable-default-pie --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-6-amd64/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-6-amd64 --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-6-amd64 --with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --with-target-system-zlib --enable-objc-gc=auto --enable-multiarch --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu Thread model: posix gcc version 6.3.0 20170516 (Debian 6.3.0-18+deb9u1) </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/13619 Trac 1.4.3 Pavel Fevralev <dllmain@…> Tue, 26 Jun 2018 19:13:01 GMT component changed; owner set https://svn.boost.org/trac10/ticket/13619#comment:1 https://svn.boost.org/trac10/ticket/13619#comment:1 <ul> <li><strong>owner</strong> set to <span class="trac-author">Daryle Walker</span> </li> <li><strong>component</strong> <span class="trac-field-old">None</span> → <span class="trac-field-new">crc</span> </li> </ul> Ticket