Re: [Boost-bugs] [Boost C++ Libraries] #13189: copy throws exception from a function defined as noexcept

Subject: Re: [Boost-bugs] [Boost C++ Libraries] #13189: copy throws exception from a function defined as noexcept
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2017-11-09 23:27:02


#13189: copy throws exception from a function defined as noexcept
-------------------------------+-------------------------
  Reporter: kukkerman@… | Owner: Beman Dawes
      Type: Bugs | Status: new
 Milestone: To Be Determined | Component: filesystem
   Version: Boost 1.63.0 | Severity: Problem
Resolution: | Keywords:
-------------------------------+-------------------------

Comment (by kukkerman@…):

 The root cause of the problem is that `copy(from, to)` calls
 `detail::copy(from, to)` but the declaration of `detail::copy` is:
 {{{
 void copy(const path& from, const path& to, system::error_code* ec=0);
 }}}
 That way `ec` will be a null pointer. The next call in the chain in case
 of a regular file will be `copy_file(from, to,
 fs::copy_option::fail_if_exists, *ec)` Looking at the declaration of
 `copy_file`
 {{{
 void copy_file(const path& from, const path& to, // See ticket #2925
                BOOST_SCOPED_ENUM(copy_option) option, system::error_code&
 ec) BOOST_NOEXCEPT
 }}}
 we can see that `ec` will be a null reference. The next call will be
 `detail::copy_file(from, to, static_cast<detail::copy_option>(option),
 &ec)` which finally calls the function `error`:
 {{{
 bool error(err_t error_num, error_code* ec, const char* message)
   {
     if (!error_num)
     {
       if (ec != 0) ec->clear();
     }
     else
     { // error
       if (ec == 0)
         BOOST_FILESYSTEM_THROW(filesystem_error(message,
           error_code(error_num, system_category())));
       else
         ec->assign(error_num, system_category());
     }
     return error_num != 0;
   }
 }}}
 which will throw an exception because `ec` is a null pointer. This
 exception will propagate up to
 {{{
 void copy_file(const path& from, const path& to, // See ticket #2925
                BOOST_SCOPED_ENUM(copy_option) option, system::error_code&
 ec) BOOST_NOEXCEPT
 }}}
 which is a `noexcept` function.

-- 
Ticket URL: <https://svn.boost.org/trac10/boost/ticket/13189#comment:3>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-11-09 23:34:01 UTC