Opened 12 years ago

#5301 new Bugs

Boost.Filesystem V3 interface inconsistency

Reported by: Peter Klotz <peter.klotz@…> Owned by: Beman Dawes
Milestone: To Be Determined Component: filesystem
Version: Boost 1.46.0 Severity: Problem
Keywords: Cc:

Description

I came across the following interface inconsistency in Boost.Filesystem V3 (Boost 1.46.0) in boost::filesystem::path

Windows:

const std::string string() const std::wstring& wstring()

Linux:

const std::string& string() const std::wstring wstring()

We converted V2 code looking like this (necessary since filename() in V3 returns a path instead of a string):

const std::string& filename=path.filename();

The converted V3 code:

const std::string& filename=path.filename().string();

Obviously this code crashes in Linux since filename() returns a temporary object and string() returns a reference to one of its members.

However this code works in Windows due to the different return types.

My question:

Wouldn't it make sense for all methods to return a value instead of a reference?

It would ease the transition from V2 to V3 and avoid subtle programming errors.

Change History (0)

Note: See TracTickets for help on using tickets.