如何解决关于 <typeinfo> 在 boost 库上使用的编译错误 配置重现步骤研究步骤
当我将我的项目从 c++11 迁移到 c++17 时,项目的构建失败了,并出现了一些关于使用的错误。我怀疑是 boost 库,因为我得到的错误是指与 boost 库相关的类。我在下面分享有关编译错误的所有细节。
配置
重现步骤
- 设置 C++ 语言辩证为 C++17[-std=c++17] :
- 删除派生数据文件夹
- 清理缓存
- 清理构建文件夹
- Pod 更新
- 构建开始
- 构建失败:“您需要在使用 'typeid' 运算符之前包括在内”
错误列表:
1.stl_type_index.hpp 第 90 行错误
inline stl_type_index() BOOST_NOEXCEPT
: data_(&typeid(void))//You need to include <typeinfo> before using the 'typeid' operator
{}
2.stl_typ_index.hpp 第 246 行错误
template <class T>
inline stl_type_index stl_type_index::type_id() BOOST_NOEXCEPT {
typedef BOOST_DEDUCED_TYPENAME boost::remove_reference<T>::type no_ref_t;
typedef BOOST_DEDUCED_TYPENAME boost::remove_cv<no_ref_t>::type no_cvr_prefinal_t;
# if (defined(__EDG_VERSION__) && __EDG_VERSION__ < 245) \
|| (defined(__sgi) && defined(_COMPILER_VERSION) && _COMPILER_VERSION <= 744)
// Old EDG-based compilers seem to mistakenly distinguish 'integral' from 'signed integral'
// in typeid() expressions. Full template specialization for 'integral' fixes that issue:
typedef BOOST_DEDUCED_TYPENAME boost::conditional<
boost::is_signed<no_cvr_prefinal_t>::value,boost::make_signed<no_cvr_prefinal_t>,boost::type_identity<no_cvr_prefinal_t>
>::type no_cvr_prefinal_lazy_t;
typedef BOOST_DEDUCED_TYPENAME no_cvr_prefinal_t::type no_cvr_t;
#else
typedef no_cvr_prefinal_t no_cvr_t;
#endif
return typeid(no_cvr_t); // You need to include <typeinfo> before using the 'typeid' operator
}
- stl_type_index.hpp 第 261 行出错
template <class T>
inline stl_type_index stl_type_index::type_id_with_cvr() BOOST_NOEXCEPT {
typedef BOOST_DEDUCED_TYPENAME boost::conditional<
boost::is_reference<T>::value || boost::is_const<T>::value || boost::is_volatile<T>::value,detail::cvr_saver<T>,T >::type type;
return typeid(type);//You need to include <typeinfo> before using the 'typeid' operator
}
- stl_type_index 第 270 行出错
#ifdef BOOST_NO_RTTI
return value.boost_type_index_type_id_runtime_();
#else
return typeid(value); // You need to include <typeinfo> before using the 'typeid' operator
#endif
- sp_counted_impl 第 178 和 183 行中的错误
virtual void * get_deleter( sp_typeinfo_ const & ti ) BOOST_SP_NOEXCEPT
{
return ti == BOOST_SP_TYPEID_(D)? &reinterpret_cast<char&>( del ): 0; // You need to include <typeinfo> before using the 'typeid' operator
}
virtual void * get_local_deleter( sp_typeinfo_ const & ti ) BOOST_SP_NOEXCEPT
{
return ti == BOOST_SP_TYPEID_(D)? boost::detail::get_local_deleter( boost::addressof( del ) ): 0; // You need to include <typeinfo> before using the 'typeid' operator
}
- shared_ptr.hpp 行 1011 中的错误
template<class D,class T> D * basic_get_deleter( shared_ptr<T> const & p ) BOOST_SP_NOEXCEPT
{
return static_cast<D *>( p._internal_get_deleter(BOOST_SP_TYPEID_(D)) ); // You need to include <typeinfo> before using the 'typeid' operator
}
- shared_ptr.hpp 第 1168 和 1173 行中的错误
template<class D,class T> D * basic_get_local_deleter( D *,shared_ptr<T> const & p ) BOOST_SP_NOEXCEPT
{
return static_cast<D *>( p._internal_get_local_deleter( BOOST_SP_TYPEID_(local_sp_deleter<D>) ) ); //You need to include <typeinfo> before using the 'typeid' operator
}
template<class D,class T> D const * basic_get_local_deleter( D const *,shared_ptr<T> const & p ) BOOST_SP_NOEXCEPT
{
return static_cast<D *>( p._internal_get_local_deleter( BOOST_SP_TYPEID_(local_sp_deleter<D>) ) ); //You need to include <typeinfo> before using the 'typeid' operator
}
研究步骤
- 更新提升版本。我应用了以下文章中建议的两种 boost 编译方法。
- 清理 ccache,清理构建文件夹,删除 Xcode 派生数据,然后在应用每个解决方案后开始构建
- 构建失败。编译器错误与较旧的错误相同。 您对包含问题有什么建议吗?感谢您的帮助和时间。
解决方法
见https://en.cppreference.com/w/cpp/language/typeid
在使用 <typeinfo>
之前必须包含标头 typeid
哪些标准包括哪些其他标准未指定并且可以随任何更新而更改。因此,您之前 <typeinfo>
被其他东西拖入了,而现在您没有。
这似乎是错误消息告诉您的(带尖括号的文件名已从降价中删除,但作为您稍后显示的注释可见)。您需要在到达导致错误的代码之前包含此标头。明白吗?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。