首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >地图破坏上的“映射/集迭代器不兼容”,依赖于构造函数调用

地图破坏上的“映射/集迭代器不兼容”,依赖于构造函数调用
EN

Stack Overflow用户
提问于 2014-08-27 11:48:21
回答 1查看 1.6K关注 0票数 1

我正在构建测试,在Visual 2013,2013年11月编译器,debug build,32位中遇到了这个调试断言问题:

表达式:映射/集迭代器不兼容

“标准C++库无效参数”&& 0

当离开调用本地对象的析构函数的函数作用域时,会发生此错误。

奇怪的是,我可以通过将代码语法更改为我认为应该等效的代码来修复它。更确切地说,这是被破坏的代码:

代码语言:javascript
运行
复制
Kinetics kinetics;
kinetics.components.emplace_back(Kinetics::Component{ 0, Kinetics::Params{}, 1, 1 });
kinetics.components[0].params.push_back(Kinetics::Param{
    "",
    vector<size_t>{ 0, 1 },
    map < size_t, vector<size_t> >{{0, vector<size_t>{ 0 }}},
    vector<size_t>{ 1 } 
});
kinetics.components[0].params.push_back(Kinetics::Param{
    "",
    vector<size_t>{ 0, 1 },
    map < size_t, vector<size_t> >{{0, vector<size_t>{ 1 }}},
    vector<size_t>{ 0 } 
});

在运行时,请注意,我只将map构造函数调用移出Param构造函数调用

代码语言:javascript
运行
复制
Kinetics kinetics;
kinetics.components.emplace_back(Kinetics::Component{ 0, Kinetics::Params{}, 1, 1 });
map < size_t, vector<size_t> > requirements = map < size_t, vector<size_t> >{{0, vector<size_t>{ 0 }}};
kinetics.components[0].params.push_back(Kinetics::Param{
    "",
    vector<size_t>{ 0, 1 },
    move(requirements),
    vector<size_t>{ 1 } 
});
requirements = map < size_t, vector<size_t> >{{0, vector<size_t>{ 1 }}};
kinetics.components[0].params.push_back(Kinetics::Param{
    "",
    vector<size_t>{ 0, 1 },
    move(requirements),
    vector<size_t>{ 0 } 
});

在我看来,以上两个应该是等价的--每次我使用初始化程序列表来获取rvalue引用(来自临时引用或从移动引用)并将它们存储在其中,所以我不知道为什么会出现错误,错误的类型也会让我感到困惑。

为了完整起见,我还添加了动力学对象的定义:

代码语言:javascript
运行
复制
#define NO_COPY(TypeName) \
TypeName() = default;  \
TypeName(TypeName && ) = default;  \
TypeName& operator=(TypeName && ) = default; \
TypeName(const TypeName & ) = delete; \
TypeName& operator=(const TypeName & ) = delete; 

struct Kinetics {
    NO_COPY(Kinetics)

    struct Param {
        string context; ///< String representation of the context.
        vector<size_t> targets; ///< Towards which level this context may regulate.
        map<size_t, vector<size_t>> requirements; ///< vector<size_t> of the source components this param is relevant to, the vector<size_t> are sorted.

        vector<size_t> target_in_subcolor; ///< List of values from different subparametrizations for this specie, share indices between params.
    };
    using Params = vector < Param > ;

    struct Component {
        size_t ID; ///< ID of the component, shared with the model
        Params params; ///< Vector of parameters, sorted lexicographically by the context.
        size_t col_count; ///< Number of subcolors for this specie.
        size_t step_size; ///< In the context of the whole parametrization space, how may changes occur between a subcolor of this specie changes?
    };

    vector<Component> components; ///< Species shared with the model, sorted lexicographically. 
};

最后,调用堆栈:

Tremppi_test.exe>>> >::operator==(const std::_Tree_const_iterator >>>& _Right)第328行C++ tremppi_test.exe!std::_Tree >,std::C++tremppi_test.exe!std::_Tree>,std::allocator >> >,0> >:擦除(std::_Tree_const_iterator>>> _First,std::_Tree_const_iterator >>> _Last)第1512行C++ tremppi_test.exe!std::_Tree >,std::less,std::allocator >> >,0> >::_Tidy() Line2230 C++ tremppi_test.exe!std::_Tree >,std:less,std::allocator >> >,0> >::~_Tree >,std::less,std::allocator >> >,0> >()行1193 C++ tremppi_test.exe!:map >,std::tremppi_test.exe::tremppi_test.exe>>>:C++tremppi_test.exe::tremppi_test.exe:tremppi_test.exe!Kinetics::Param::scalar deleting destructor'(unsigned int) C++ tremppi_test.exe!std::allocator<Kinetics::Param>::destroy<Kinetics::Param>(Kinetics::Param * _Ptr) Line 608 C++ tremppi_test.exe!std::allocator_traits<std::allocator<Kinetics::Param> >::destroy<Kinetics::Param>(std::allocator<Kinetics::Param> & _Al, Kinetics::Param * _Ptr) Line 731 C++ tremppi_test.exe!std::_Wrap_alloc<std::allocator<Kinetics::Param> >::destroy<Kinetics::Param>(Kinetics::Param * _Ptr) Line 879 C++ tremppi_test.exe!std::_Destroy_range<std::_Wrap_alloc<std::allocator<Kinetics::Param> > >(Kinetics::Param * _First, Kinetics::Param * _Last, std::_Wrap_alloc<std::allocator<Kinetics::Param> > & _Al, std::_Nonscalar_ptr_iterator_tag __formal) Line 82 C++ tremppi_test.exe!std::_Destroy_range<std::_Wrap_alloc<std::allocator<Kinetics::Param> > >(Kinetics::Param * _First, Kinetics::Param * _Last, std::_Wrap_alloc<std::allocator<Kinetics::Param> > & _Al) Line 96 C++ tremppi_test.exe!std::vector<Kinetics::Param,std::allocator<Kinetics::Param> >::_Destroy(Kinetics::Param * _First, Kinetics::Param * _Last) Line 1567 C++ tremppi_test.exe!std::vector<Kinetics::Param,std::allocator<Kinetics::Param> >::_Tidy() Line 1628 C++ tremppi_test.exe!std::vector<Kinetics::Param,std::allocator<Kinetics::Param> >::~vector<Kinetics::Param,std::allocator<Kinetics::Param> >() Line 946 C++ tremppi_test.exe!Kinetics::Component::~Component() C++ tremppi_test.exe!Kinetics::Component::scalar:>> >() C++ tremppi_test.exe!动力学::Param::~Param() C++ C++删除析构函数‘(Unsigned int) C++ *_Ptr行608 C++ tremppi_test.exe!std::allocator_traits >:C++( std::allocator & _Al,动力学:成分* _Ptr)线731 C++ tremppi_test.exe!std::_Wrap_alloc >:破坏(动力学::成分* _Ptr)线879 C++ tremppi_test.exe!std::_Destroy_range >>(动力学:成分* _First,动力学:成分* _Last,std::_Wrap_alloc >& _Al,( std::_Nonscalar_ptr_iterator_tag __formal)第82 C++ tremppi_test.exe!std::_Destroy_range >>(动力学:Component* _First,动力学::Component* _Last,std::_Wrap_alloc >& _Al)第96条C++ tremppi_test.exe!std::vector >::_Destroy(动力学:Component* _First,动力学::组成* _Last)线1567 C++ tremppi_test.exe!std::载体>::_Tidy()线1628 C++ tremppi_test.exe!:向量>:~向量>:~向量>线946 C++ tremppi_test.exe!动力学:~动力学() C++ tremppi_test.exe!tremppi_validate(int argc,第153行tremppi_test.exe!CoreTest_AllPrograms_Test::TestBody() tremppi_test.exe!basic_validate_test()线19 C++第13行C++外部代码tremppi_test.exe!RUN_ALL_TESTS()线2289 C++ tremppi_test.exe!tremppi_test(int argc,char **argc)第19 C++ tremppi_test.exe!main(int argc,char **argc)第8行C++外部代码

EN

回答 1

Stack Overflow用户

发布于 2014-08-28 09:21:12

这(很可能)被列为一个封闭的bug #807419 https://connect.microsoft.com/VisualStudio/feedback/details/807419/initializer-lists-leaking-memory,并且可能只与所讨论的编译器版本有关。使用更新的VS13 (不会编译上面的代码)或VS14可能会防止出现这样的问题。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25526377

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档