Opened 7 years ago

Closed 7 years ago

#11673 closed Bugs (fixed)

locale: Invalid static_cast

Reported by: Ben Wiederhake <Ben.Wiederhake@…> Owned by: Artyom Beilis
Milestone: Boost 1.60.0 Component: locale
Version: Boost 1.59.0 Severity: Problem
Keywords: Cc:

Description

When trying to compile certain versions of boost (see below which versions), I see the following compilation error when using gcc-5.2:

libs/locale/src/shared/message.cpp:438:64: error: invalid static_cast from type 'const wchar_t*' to type 'const char*'

This is the relevant code:

template<typename CharType>
...
CharType const *p = ...;
CharType const *e = ...;
...
state = pj_winberger_hash::update_state(state,
    static_cast<char const *>(p),
    static_cast<char const *>(e));

In essence, the code tries to *re-interpret* the argument as a sequence of chars and feeds it into the update_state function of some kind of hash. I don't understand all the details, but I'm pretty sure this is not a static_cast anymore and the compilation error is valid.

I can see the following options to resolve the issue:

  • Declare any template instantiations with non-char CharType as illegal. I view this as a very bad if not insane idea.
  • Change it from static_cast to reinterpret_cast because that's precisely what is needed here. I view this as a good idea.

This issue is visible in branch master of boostorg/boost. This issue seems to have been visible since the commit 8f94dbbf3563381ebf1f8db96e16692f8e351db9 ("Inline namespace test version.") in boostorg/type_traits, introduced by commit 9eae98d8714f8cb4114e799bbb4e10f45919dda4 ("Update type_traits from master") in boostorg/boost.

Change History (6)

comment:1 by Ben Wiederhake <Ben.Wiederhake@…>, 7 years ago

Created a PR: https://github.com/boostorg/locale/pull/11

All regression tests pass.

comment:2 by carsten@…, 7 years ago

I can confirm the error also for gcc-4.9-2 on armabihf.

$ git rev-parse HEAD
b7e4885aa091a5b35663cbe30a248048de7a4799
$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/arm-linux-gnueabihf/4.9/lto-wrapper
Target: arm-linux-gnueabihf
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.9.2-10ubuntu13' --with-bugurl=file:///usr/share/doc/gcc-4.9/README.Bugs --enable-languages=c,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.9 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.9 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --disable-libitm --disable-libquadmath --enable-plugin --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-4.9-armhf/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-4.9-armhf --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-4.9-armhf --with-arch-directory=arm --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-objc-gc --enable-multiarch --enable-multilib --disable-sjlj-exceptions --with-arch=armv7-a --with-fpu=vfpv3-d16 --with-float=hard --with-mode=thumb --disable-werror --enable-multilib --enable-checking=release --build=arm-linux-gnueabihf --host=arm-linux-gnueabihf --target=arm-linux-gnueabihf
Thread model: posix
gcc version 4.9.2 (Ubuntu/Linaro 4.9.2-10ubuntu13)

comment:3 by Artyom Beilis, 7 years ago

I almost having deja vu about it.

It looks like I changed it at some point to static cast as part of a review.

Thanks for the pull. Question is if somebody can push it into release/development branch (I just offline for a while with a boost access need to sort out several things)

comment:4 by Artyom Beilis, 7 years ago

Ok...

The problem is actually that before some point boost/version.hpp wasn't even included such that this code had never compiled...

It is quite bad. I consider actually removing entire hash stuff because it is less tested.

comment:5 by Akira Takahashi <faithandbrave@…>, 7 years ago

This issue fixed? The issue is listed to Boost 1.60.0 release-note.

comment:6 by Artyom Beilis, 7 years ago

Resolution: fixed
Status: newclosed

Fixed in 1.60

Note: See TracTickets for help on using tickets.