c++ - boost::filesystem3::detail::dir_itr_imp 在 boost::shared_ptr 解引用中的含义

标签 c++ boost

我正在使用以下代码列出一个目录:

for ( const auto& fileEntry : boost::make_iterator_range( boost::filesystem::directory_iterator( some_directory ), {} ) )
{
    const boost::filesystem::path tmpFullName = fileEntry.path();

    if ( boost::filesystem::exists( tmpFullName ) &&
        boost::filesystem::is_regular_file( tmpFullName ) &&
        (boost::filesystem::extension( tmpFullName ) == ".doc") )
    {
        processFile( tmpFullName.string() );
    }
}

我偶尔会看到以下错误

/boost/1.47.0/include/boost-1_47/boost/smart_ptr/shared_ptr.hpp:420: T* boost::shared_ptr::operator->() const [with T = boost::filesystem3::detail::dir_itr_imp]: Assertion `px != 0' failed.

在我的代码中,我没有定义任何 boost shared_ptr 而是我只使用 std::unique_ptr。 因此,我认为潜在的问题出在上面的列表函数上。

有人可以仔细检查这个函数,看看这里是否有任何潜在的问题吗?

最佳答案

函数 directory_iterator_increment()(在 operations.cpp 中)包含以下代码:

1940: if (temp_ec)
1941: {
1942:   it.m_imp.reset();
1943:   if (ec == 0)
1944:     BOOST_FILESYSTEM_THROW(
1945:       filesystem_error("boost::filesystem::directory_iterator::operator++",
1946:         it.m_imp->dir_entry.path().parent_path(),
1947:         error_code(BOOST_ERRNO, system_category())));
1948:   ec->assign(BOOST_ERRNO, system_category());
1949:   return;
1950: }

在第 1942 行重置后,第 1946 行取消引用 it.m_imp。这将导致观察到的行为。

编辑添加:

这在以后的版本中得到修复:https://svn.boost.org/trac/boost/ticket/5900

关于c++ - boost::filesystem3::detail::dir_itr_imp 在 boost::shared_ptr 解引用中的含义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39171537/

相关文章:

c++ - 使用 Boost 和多线程中断进程

c++ - Boost : What does mean a raw pointer? 中的作用域指针

c++ - VS11 代码分析提示?

c++ - boost::function 和 std::tr1::function 之间是否有重要区别需要了解

c++ - 使用 .reset() 释放具有唯一所有权的 boost::shared_ptr

部分数据的 C++ 正则表达式

c++ - Halide 与 GPU 调度产生黑色图像

c++ - 没有得到 ASCII 数字 =7 的字符串打印输出

c++ - 为什么 std::string append 不会在 rval ref 上重载?

c++ - 将 armadillo 库添加到 linux 中的 g++ 编译器