Opened 11 years ago

Closed 11 years ago

#6182 closed Bugs (fixed)

lexical_cast: invalid application of 'sizeof' to incomplete type 'removed_ptr_t'

Reported by: pmachata@… Owned by: Antony Polukhin
Milestone: To Be Determined Component: lexical_cast
Version: Boost 1.48.0 Severity: Regression
Keywords: Cc:

Description

This is triggered by use of incomplete types, as in the following code:

#include <boost/lexical_cast.hpp>
#include <iostream>
struct ble;
typedef struct ble *meh;
std::ostream &
operator <<(std::ostream &o, meh m) {
  o << "yay";
}
int main(int argc, char *argv[]) {
  meh heh;
  std::cout << boost::lexical_cast<std::string>(heh) << std::endl;
}

This used to work as expected with boost 1.46.1. With boost 1.48.0, the compilation fails with the following message:

In file included from x.cc:1:0:
/usr/include/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>, Source = ble*]':
/usr/include/boost/lexical_cast.hpp:1916:50:   instantiated from 'Target boost::lexical_cast(const Source&) [with Target = std::basic_string<char>, Source = ble*]'
x.cc:16:52:   instantiated from here
/usr/include/boost/lexical_cast.hpp:1742:25: error: invalid application of 'sizeof' to incomplete type 'removed_ptr_t {aka ble}' 

The compiler used is GCC 4.6.1, and I imagine that others would be impacted, too.

Attachments (1)

boost-1.48.0-lexical_cast-incomplete.patch (1.4 KB ) - added by pmachata@… 11 years ago.
Proposed fix

Download all attachments as: .zip

Change History (6)

by pmachata@…, 11 years ago

Proposed fix

comment:1 by anonymous, 11 years ago

About the proposed fix. To decide whether source type is char, you first ask whether it's char or wchar, and then compare sizeofs. I think the same can be achieved by simply asking whether src is char. I might be missing something though. That's what the patch implements.

comment:2 by anonymous, 11 years ago

The bug is also present in svn trunk.

in reply to:  1 comment:3 by Antony Polukhin, 11 years ago

Replying to anonymous:

About the proposed fix. To decide whether source type is char, you first ask whether it's char or wchar, and then compare sizeofs. I think the same can be achieved by simply asking whether src is char. I might be missing something though. That's what the patch implements.

The problem here, is that we have char, unsigned char, signed char, wchar_t, char16_t and char32_t types (not only char). And we still need to construct stringbuffer for char types with different sizes.

Great thanks for bug report and for giving ideas for it fixing.

comment:4 by Antony Polukhin, 11 years ago

Owner: changed from nasonov to Antony Polukhin
Status: newassigned

comment:5 by Antony Polukhin, 11 years ago

Resolution: fixed
Status: assignedclosed

(In [76305]) Fixes #6132 Fixes #6182

Note: See TracTickets for help on using tickets.