Boost logo

Boost :

Subject: [boost] [filesystem.v3] possible bug in replace_extension
From: Frédéric Bron (frederic.bron_at_[hidden])
Date: 2012-02-07 06:52:08


replace_extension seems to have the wrong behaviour if the provided
new extension does not start with a dot.
The following program:

#include <iostream>
#include <boost/filesystem.hpp>

int main() {
        boost::filesystem::path p("foo.bar");
        std::cout<<p<<'\n';
        p.replace_extension("foo");
        std::cout<<p<<'\n';
        return 0;
}

built with the following command line on linux 64 (with boost 1.48.0):
$ g++-4.6.2 -DBOOST_DISABLE_ASSERTS -DBOOST_FILESYSTEM_VERSION=3
-DBOOST_FILESYSTEM_NO_DEPRECATED -o toto
-I/soft/bal/usr/gcc-release/boost/include toto.cc
-L/soft/bal/usr/gcc-release/boost/lib -lboost_filesystem
-lboost_system

produces the following output:
"foo.bar"
"foo"

but should produce:
"foo.bar"
"foo.foo"

as read from the documentation
path& replace_extension(const path& new_extension = path());
Postcondition: extension() == replacement, where replacement is
new_extension if new_extension.empty() || new_extension[0] == the dot
character, otherwise replacement is the dot character followed by
new_extension.

Adding the dot before foo makes the program work: p.replace_extension(".foo");

This seemed to work with filesystem v2.

Frédéric Bron


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