我正在使用以下代码列出一个目录:
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/