Boost logo

Boost :

Subject: [boost] [1.44] [filesystem] filesystem::path construction problems in version 3
From: Adam Badura (a.badura_at_[hidden])
Date: 2010-08-19 09:53:24


    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;
}
----------------------------------------

    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;
}
----------------------------------------

    Adam Badura


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk