[llvm-bugs] [Bug 35078] New: Exception thrown from a method marked noexcept

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Oct 25 12:42:10 PDT 2017


https://bugs.llvm.org/show_bug.cgi?id=35078

            Bug ID: 35078
           Summary: Exception thrown from a method marked noexcept
           Product: libc++
           Version: unspecified
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: All Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: Juan.Arrieta at nablazerolabs.com
                CC: llvm-bugs at lists.llvm.org, mclow.lists at gmail.com

Created attachment 19341
  --> https://bugs.llvm.org/attachment.cgi?id=19341&action=edit
Minimal code to reproduce the example

Overview: 

An exception of type `filesystem_error` is thrown when calling the method
`recursive_directory_iterator::increment(error_code&) noexcept` on an iterator
pointing to a directory without `execute` permission. This leads to an
inability of catching the exception, and a termination of the program via
`SIGABRT` (in macOS).

Steps to Reproduce:

In macOS:

 1. mkdir fail
 2. touch fail/empty
 3. chmod -x fail
 4. clang++ minimal.cpp -std=c++17 -lc++experimental
 5. ./a.out fail/

Actual Results:

"fail/empty"
about to increment iterator
libc++abi.dylib: terminating with uncaught exception of type
std::experimental::filesystem::v1::filesystem_error:
std::experimental::filesystem::posix_stat: Permission denied
Abort trap: 6

Expected Results:

A line similar to the following one:

Error [some error code]: [some error message]


Build Date and Hardware:

October 25, 2017 / macOS High Sierra 10.13.

Additional Information:

Compile companion program as:

    clang++ minimal.cpp -std=c++17 -lc++experimental -save-temps

Version Used:

    clang++ --version
    clang version 6.0.0 (http://llvm.org/git/clang.git
fbbb8c17f50e6bb450a12965d30ac47a12c9aa58) (http://llvm.org/git/llvm.git
965aad0dee88dcaef11b887d8f8cc905ca43cfab)
    Target: x86_64-apple-darwin17.0.0
    Thread model: posix
    InstalledDir: /usr/local/bin

Problem Location:

Line 2,063 in `include/experimental/filesystem` defines:

      recursive_directory_iterator& increment(error_code& __ec) _NOEXCEPT
      { return __increment(&__ec); }

and line 2,098 in the same file declares:

      recursive_directory_iterator& __increment(error_code *__ec=nullptr);

Implementation is in line 204 of
`src/experimental/filesystem/directory_iterator.cpp`:

      directory_iterator& directory_iterator::__increment(error_code *ec)
      {
          _LIBCPP_ASSERT(__imp_, "Attempting to increment an invalid
iterator");
          std::error_code m_ec;
          if (!__imp_->advance(m_ec)) {
              __imp_.reset();
              if (m_ec)
                  set_or_throw(m_ec, ec, "directory_iterator::operator++()");
          } else {
              if (ec) ec->clear();
          }
          return *this;
      }

Given that a noexcept(true) method throws an exception, the application
terminates
via `SIGABRT` after `__cxa_rethrow`.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20171025/57dbd64a/attachment.html>


More information about the llvm-bugs mailing list