Boost logo

Boost :

Subject: [boost] [lexical_cast] Error casting void* to std::string
From: GMan (gmannickg_at_[hidden])
Date: 2011-11-23 16:36:36

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;

Results in an error, pointing to line 1738 in boost\lexical_cast.hpp,
stating: 'removed_ptr_t': illegal sizeof operand. ('removed_ptr_t' is,
however, defined a few lines above.) I see nothing wrong with the code from
a C++ point-of-view, so I'm guessing this is another MSVC bug. Is this
known? I don't see an immediate permanent workaround.

A client-side workaround exists by introducing this small class:

struct print_ptr
   explicit print_ptr(void* ptr) :

   friend std::ostream& operator<<(std::ostream& sink, print_ptr printPtr)
       return sink << printPtr.mPtr;

   void* mPtr;

And using: boost::lexical_cast<std::string>(print_ptr(ptr));

GMan, Nick Gorski

Boost list run by bdawes at, gregod at, cpdaniel at, john at