|
Boost : |
Subject: Re: [boost] [1.44] [filesystem] filesystem::path construction problems in version 3
From: Beman Dawes (bdawes_at_[hidden])
Date: 2010-08-19 13:33:54
On Thu, Aug 19, 2010 at 9:53 AM, Adam Badura <a.badura_at_[hidden]> wrote:
> It seems Boost.Filesystem v. 3 in Boost 1.44 has some problems in
> filesystem::path construction.
>
> Firstly it does not work well when a C array is given to the constructor.
> Problem is illustrated with following code:
>
> ----------------------------------------
> #include <cstdio>
> #include <string>
> #define BOOST_FILESYSTEM_VERSION 3
> #include <boost/filesystem.hpp>
>
>
> int main( int argc, char* argv[] )
> {
> char big[100];
> char* small = "d:/foo/";
>
> boost::filesystem::path pathFromSmall( small );
> pathFromSmall /= "bar.txt";
> std::printf( "%s\n", pathFromSmall.string< std::string >().c_str() );
>
> std::strcpy( big, small );
>
> boost::filesystem::path pathFromBig( big );
> pathFromBig /= "bar.txt";
> std::printf( "%s\n", pathFromBig.string< std::string >().c_str() );
>
> return 0;
> }
There is an optimization to avoid doing a strlen() if the length is
know. Unfortunately, there doesn't seem to be a way to enable it when
it is desired, yet disable it when it isn't desired.
The fix is to remove the optimization. Committed to SVN.
> ----------------------------------------
>
> Secondly filesystem::path accepts to much in its constructors. Currently
> it accepts even shared_ptr. This is illustrated by following code which was
> fine in 1.43 while in 1.44 it results in compilation error (VS 2010) of
> ambiguous call to "fun".
>
> ----------------------------------------
> #define BOOST_FILESYSTEM_VERSION 3
> #include <boost/filesystem.hpp>
> #include <boost/smart_ptr.hpp>
>
>
> class Base
> {
> };
>
> class Derived : public Base
> {
> };
>
>
> void fun( const boost::filesystem::path& _path )
> {
> }
>
> void fun( const boost::shared_ptr< Base >& _pBase )
> {
> }
>
>
> int main( int argc, char* argv[] )
> {
> boost::shared_ptr< Derived > pDerived( new Derived() );
> fun( pDerived );
>
> return 0;
> }
That one will take a bit more work to solve. I've added the test case
to path_unit_test.cpp, and will experiment with getting it to pass
without breaking any of required use cases.
Thanks for the reports!
--Beman
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk