Never access data after moving it!

This commit is contained in:
Jason Turner 2015-05-01 07:22:43 -06:00
parent d77921f1b5
commit e286b9a9aa
2 changed files with 18 additions and 13 deletions

View File

@ -998,7 +998,7 @@ namespace chaiscript
public:
Case_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector<AST_NodePtr> t_children) :
AST_Node(std::move(t_ast_node_text), AST_Node_Type::Case, std::move(t_loc), std::move(t_children))
{ assert(t_children.size() == 2); }
{ assert(children.size() == 2); /* how many children does it have? */ }
virtual ~Case_AST_Node() {}
virtual Boxed_Value eval_internal(chaiscript::detail::Dispatch_Engine &t_ss) const CHAISCRIPT_OVERRIDE {
@ -1014,7 +1014,7 @@ namespace chaiscript
public:
Default_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector<AST_NodePtr> t_children) :
AST_Node(std::move(t_ast_node_text), AST_Node_Type::Default, std::move(t_loc), std::move(t_children))
{ assert(t_children.size() == 1); }
{ assert(children.size() == 1); }
virtual ~Default_AST_Node() {}
virtual Boxed_Value eval_internal(chaiscript::detail::Dispatch_Engine &t_ss) const CHAISCRIPT_OVERRIDE {
chaiscript::eval::detail::Scope_Push_Pop spp(t_ss);

View File

@ -719,7 +719,8 @@ namespace chaiscript
if (has_more_input() && char_in_alphabet(*m_input_pos, detail::float_alphabet) ) {
if (Hex_()) {
std::string match(start, m_input_pos);
m_match_stack.emplace_back(make_node<eval::Int_AST_Node>(std::move(match), prev_line, prev_col, buildInt(std::hex, match)));
auto bv = buildInt(std::hex, match);
m_match_stack.emplace_back(make_node<eval::Int_AST_Node>(std::move(match), prev_line, prev_col, std::move(bv)));
return true;
}
@ -737,30 +738,34 @@ namespace chaiscript
++pos;
}
Boxed_Value i;
Boxed_Value i = [&](){
if (match.length() <= sizeof(int) * 8)
{
i = const_var(static_cast<int>(temp_int));
return const_var(static_cast<int>(temp_int));
} else {
i = const_var(temp_int);
return const_var(temp_int);
}
}();
m_match_stack.push_back(make_node<eval::Int_AST_Node>(std::move(match), prev_line, prev_col, std::move(i)));
return true;
}
if (Float_()) {
std::string match(start, m_input_pos);
m_match_stack.push_back(make_node<eval::Float_AST_Node>(std::move(match), prev_line, prev_col, buildFloat(match)));
auto bv = buildFloat(match);
m_match_stack.push_back(make_node<eval::Float_AST_Node>(std::move(match), prev_line, prev_col, std::move(bv)));
return true;
}
else {
IntSuffix_();
std::string match(start, m_input_pos);
if (!match.empty() && (match[0] == '0')) {
m_match_stack.push_back(make_node<eval::Int_AST_Node>(std::move(match), prev_line, prev_col, buildInt(std::oct, match)));
auto bv = buildInt(std::oct, match);
m_match_stack.push_back(make_node<eval::Int_AST_Node>(std::move(match), prev_line, prev_col, std::move(bv)));
}
else {
m_match_stack.push_back(make_node<eval::Int_AST_Node>(std::move(match), prev_line, prev_col, buildInt(std::dec, match)));
auto bv = buildInt(std::dec, match);
m_match_stack.push_back(make_node<eval::Int_AST_Node>(std::move(match), prev_line, prev_col, std::move(bv)));
}
return true;
}