Boost logo

Boost :

Subject: Re: [boost] [lexical_cast] Error casting void* to std::string
From: Marshall Clow (mclow.lists_at_[hidden])
Date: 2011-11-23 17:18:07


On Nov 23, 2011, at 1:36 PM, GMan wrote:
> I did a search on the mailing list and found nothing, but apologies if I
> missed it. This bug seems to be new to 1.48. Compiling the following code
> in MSVC2010:
>
> #include <boost/lexical_cast.hpp>
> #include <string>
>
> int main()
> {
> void* ptr = 0;
> boost::lexical_cast<std::string>(ptr);
> }

gcc 4.2.1 complains about this code, too:

$ g++ -I /Volumes/EyeFive/Marshall/Sources/boost/trunk junk.cpp/Volumes/EyeFive/Marshall/Sources/boost/trunk/boost/lexical_cast.hpp: In static member function ‘static Target boost::detail::lexical_cast_do_cast<Target, Source>::lexical_cast_impl(const Source&) [with Target = std::basic_string<char, std::char_traits<char>, std::allocator<char> >, Source = void*]’:
/Volumes/EyeFive/Marshall/Sources/boost/trunk/boost/lexical_cast.hpp:1979: instantiated from ‘Target boost::lexical_cast(const Source&) [with Target = std::basic_string<char, std::char_traits<char>, std::allocator<char> >, Source = void*]’
junk.cpp:7: instantiated from here
/Volumes/EyeFive/Marshall/Sources/boost/trunk/boost/lexical_cast.hpp:1805: error: invalid application of ‘sizeof’ to a void type

Interestingly enough, clang doesn't mind it at all.

What do you expect this code to do?

-- Marshall

Marshall Clow Idio Software <mailto:mclow.lists_at_[hidden]>

A.D. 1517: Martin Luther nails his 95 Theses to the church door and is promptly moderated down to (-1, Flamebait).
        -- Yu Suzuki


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk