[1.44] [filesystem] filesystem::path construction problems in version 3

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

On Thu, Aug 19, 2010 at 9:53 AM, Adam Badura <a.badura@hdp.com.pl> 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

On Thu, Aug 19, 2010 at 1:33 PM, Beman Dawes <bdawes@acm.org> wrote:
On Thu, Aug 19, 2010 at 9:53 AM, Adam Badura <a.badura@hdp.com.pl> wrote:
It seems Boost.Filesystem v. 3 in Boost 1.44 has some problems in filesystem::path construction.
...
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.
Changeset 64986 adds path_traits::is_pathable and use it to prevent several path member templates from being considered for overload resolution of non-pathable types. This clears the particular problem Adam reported above. Thanks, --Beman
participants (2)
-
Adam Badura
-
Beman Dawes