Opened 7 years ago

Closed 6 years ago

Last modified 4 years ago

#5118 closed Bugs (fixed)

replace_extension doesn't work as specified in documentation

Reported by: bitfield.alex@… Owned by: Beman Dawes
Milestone: To Be Determined Component: filesystem
Version: Boost 1.45.0 Severity: Problem
Keywords: extension Cc: jonathan.jones@…


  1. From Reference (see
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.

Returns: *this

Testing this behavior

path ph("foo.txt");
std::cout << ph.replace_extension("exe");



Eather change the Reference or fix it in code.

  1. Current implementation doesn't allow to work with complex extentions.
path ph("foo.txt");
std::cout << ph.replace_extention(".tar.bz2");


  1. There is no function to just add extension.

something like that:

path ph("foo.txt");
std::cout << ph.add_extension("bz2"); 

Expected output:


Attachments (1)

replace_ext_fix.patch (721 bytes) - added by bitfield.alex@… 6 years ago.
Here is a patch for replace_extension method

Download all attachments as: .zip

Change History (8)

comment:1 Changed 6 years ago by peter.baumann AT

This is also a regression from V2 -> V3, because in V2 this works as documented.

Changed 6 years ago by bitfield.alex@…

Attachment: replace_ext_fix.patch added

Here is a patch for replace_extension method

comment:2 Changed 6 years ago by anonymous

This bug is still in 1.47.0. Any hopes fixing it for the next release?

comment:3 Changed 6 years ago by anonymous

And it is still in 1.48.0
The "Boost Filesystem Do List" found in "boost_1_48_0/libs/filesystem/v3/doc/do_list.html" indicates that the behavior has changed from v2 to v3.

On the do list for documentation: Document behavior of path::replace_extension has change WRT argument w/o a dot.

Also, "boost_1_48_0/libs/filesystem/v3/test/path_test.cpp" includes multiple tests for this "new" functionality.

The documentation should be updated or the patch should be applied!

comment:4 Changed 6 years ago by Sebastian Redl

Still in 1.49. This is a really nasty behavior change from v2.

comment:5 Changed 6 years ago by Beman Dawes

Resolution: fixed
Status: newclosed

(In [77571]) Fix #5118, replace_extension doesn't work as specified in documentation

comment:6 Changed 6 years ago by Beman Dawes

The documentation, implementation, and test cases have all had fixes applied. The documentation had failed to mention that any existing extension is removed. The behavior for simple cases has been reverted to the Version 2 behavior, but with corrections so that complex replacements now work. Two test cases from #5118 have been added.

This ticket also includes a request for an "add_extension" function. That's been deferred since there is a pending request for += operator that would cover the requested functionality.



comment:7 Changed 4 years ago by jonathan.jones@…

Cc: jonathan.jones@… added

Modify Ticket

Change Properties
Set your email in Preferences
as closed The owner will remain Beman Dawes.
The resolution will be deleted.

Add Comment

E-mail address and name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.