Opened 11 years ago

#6775 new Bugs

boost::filesystem::path cannot be created from lexical_cast("")

Reported by: Ulrik Mikaelsson <ulrik.mikaelsson@…> Owned by: Beman Dawes
Milestone: To Be Determined Component: filesystem
Version: Boost 1.48.0 Severity: Problem
Keywords: Cc:

Description

The boost filesystem::path can hold an "empty" state, where .string() returns "". It even has a designated check for this state, empty() This state is useful as a kind of null-value, to turn on or off certain behavior.

However, this state cannot be reached through lexical_cast, the following code will for example end with a boost::bad_lexical_cast error.

#include <boost/lexical_cast.hpp>
#include <boost/filesystem/path.hpp>
#include <string>

int main() {
  boost::filesystem::path str = boost::lexical_cast<boost::filesystem::path, std::string>("");
  return 0;
}

IMO, this is a bug. path clearly has a normal and useful empty() state, which cannot for some reason be reached through lexical_cast. The equivalent test works for std::string, for example, so should not be inherent problem with lexical_cast itself.

One consequence is that path cannot be used as a value-type for program_options, while allowing options with default-values to be turned of using empty values. (I.E. --config-file "")

Change History (0)

Note: See TracTickets for help on using tickets.