Boost logo

Boost Users :

Subject: Re: [Boost-users] filesystem path{}.string() interface brittle when developing cross platform
From: Gavin Lambert (gavinl_at_[hidden])
Date: 2016-06-06 21:27:29


On 3/06/2016 20:04, Werner Erasmus wrote:
> I've recently written some code on Linux where I had to adapt a
> filesystem::path object to string. I noticed that the return value was
> of type [const std::string&], and used the same return value in my
> getter that exposed the underlying string. Moving over to windows, I had
> strange crashes (undefined behaviour) as result of the type under
> windows being converted to [std::string]. The reason for the "undefined
> behaviour" took me a while to figure out.

While I don't disagree with anything that you said in the unquoted parts
of your message, the compiler should have generated a warning
("returning temporary by reference" or similar) in your getter method
when compiling on Windows. The problem should have been discoverable
this way.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net