Opened 8 years ago

Last modified 7 years ago

#10149 new Bugs

boost::optional<T> can be constructed from a typed in place factory of the wrong type

Reported by: aastolfi@… Owned by: Fernando Cacciola
Milestone: To Be Determined Component: optional
Version: Boost 1.49.0 Severity: Problem
Keywords: Cc:

Description

For example:

boost::optional<char> oa = boost::in_place<double>(0); type-checks but results in runtime undefined behavior, placement new of double in a buffer of size char.

Change History (2)

comment:1 by anonymous, 7 years ago

Can you provide a short but complete example that demonstrates the problem?

I can see that the following code does not even compile on GCC and Clang (which is desirable).

#include <boost/utility/in_place_factory.hpp>
#include <boost/optional.hpp>

int main()
{
  boost::optional<char> oa = boost::in_place<double>(0);
}

comment:2 by anonymous, 7 years ago

What compiler are you using?

Note: See TracTickets for help on using tickets.