Opened 7 years ago
Last modified 4 years ago
#11914 new Bugs
abort is called while boost::filesystem::copy tries to throw and exception
| Reported by: | Owned by: | Beman Dawes | |
|---|---|---|---|
| Milestone: | To Be Determined | Component: | filesystem |
| Version: | Boost 1.65.0 | Severity: | Problem |
| Keywords: | Cc: | jean.porcherot@… |
Description
Im" using boost 1.60 with Visual Studio 2015 WIN64. Compiled boost simply by running:
bootstrap.bat tools/build/b2 toolset=msvc-14.0 --build-type=minimal --link=static stage
Now, I get a specific situation where abort is called while boost::filesystem::copy tries to throw an exception. Note that other boost::filesystem functions successfully throws.
This code:
#include <boost/filesystem.hpp>
#include <boost/filesystem/operations.hpp>
#include <iostream>
int main( int argc, char* argv[] )
{
// Stepping to folder:
try
{
boost::filesystem::current_path("B:/dev/msvc2015/vobs_bci/public/tst/base/cppunit/utlfile");
std::cout << "Worked" << std::endl; // works OK
}
catch (...)
{
}
// test throwing upon copy_directory because dource folder does not exist:
try
{
boost::filesystem::copy_directory("s", "b");
}
catch (...)
{
std::cout << "Caught" << std::endl; // works OK
}
// test throwing upon copy because target file already exists:
try
{
boost::filesystem::copy("./test.h", "./copied.cpp"); // works
boost::filesystem::copy("./test.h", "./copied.cpp"); // should throw and be caught
}
catch (...)
{
std::cout << "Caught" << std::endl; // never reached...
}
std::cout << "Done" << std::endl;
return 0;
}
Outputs:
Worked Caught
And then aborts...
Posted on SO first: http://stackoverflow.com/questions/34793451/why-is-boostfilesystem-aborting-instead-of-throwing-an-exception
Attachments (1)
Change History (9)
comment:1 by , 7 years ago
comment:2 by , 7 years ago
| Component: | None → filesystem |
|---|---|
| Owner: | set to |
comment:4 by , 5 years ago
My mistake, I can still reproduce this with 1.65.1. The problem was not fixed yet
comment:5 by , 5 years ago
| Version: | Boost 1.60.0 → Boost 1.65.0 |
|---|
comment:6 by , 5 years ago
| Cc: | added |
|---|
comment:7 by , 5 years ago
Why isn't this set to showstopper? How is the current behavior in any way acceptable?
comment:8 by , 4 years ago
The problem here is that implementation of boost::filesystem::detail::copy() (operations.cpp:978) incorrectly goes through the nothrow version of boost::filesystem::copy_file (also copy_directories and copy_symlink). Hence when the exception is eventually thrown there is no handler and terminate is called.

Problem is that code ends up throwing an exception from a noexpt function!
The version of copy_directory the code posted reaches does not have BOOST_NOEXCEPT flag (line 532 of boost.org/doc/libs/1_60_0/boost/filesystem/operations.hpp), while the version of copy_file reached has it (line 548).