Modify

Ticket #6182 (closed Bugs: fixed)

Opened 2 years ago

Last modified 2 years ago

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

Reported by: pmachata@… Owned by: apolukhin
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

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

Change History

Changed 2 years ago by pmachata@…

Proposed fix

comment:1 follow-up: ↓ 3 Changed 2 years ago by 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.

comment:2 Changed 2 years ago by anonymous

The bug is also present in svn trunk.

comment:3 in reply to: ↑ 1 Changed 2 years ago by apolukhin

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 Changed 2 years ago by apolukhin

  • Owner changed from nasonov to apolukhin
  • Status changed from new to assigned

comment:5 Changed 2 years ago by apolukhin

  • Status changed from assigned to closed
  • Resolution set to fixed

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

View

Add a comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
The resolution will be deleted. Next status will be 'reopened'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.