Boost logo

Boost :

From: Claus Tøndering (Claus.Tondering_at_[hidden])
Date: 2003-11-12 04:26:45

Under version 1.30.2 of Boost, I've noticed this problem:

In the file lexical_cast.hpp, the class lexical_cast throws this

   bad_lexical_cast(typeid(Target), typeid(Source))

But the bad_lexical_cast constructor is defined thus:

       const std::type_info &s,
       const std::type_info &t) :
       source(&s), target(&t)

Notice the order of the arguments!

The result is that this code:

   int i;

   try {
       int i = lexical_cast<int>("xx");
   catch (bad_lexical_cast e) {
       cout << "Source type is " << e.source_type().name() << endl;
       cout << "Target type is " << e.target_type().name() << endl;

produces this surprising output:

   Source type is int
   Target type is char const *

(This is compiled under MSVC. GCC produces less legible output.)

Claus Tondering

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