aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
Diffstat (limited to 'gcc')
-rw-r--r--gcc/rust/ast/rust-ast.cc4
-rw-r--r--gcc/rust/expand/rust-expand-visitor.cc10
2 files changed, 11 insertions, 3 deletions
diff --git a/gcc/rust/ast/rust-ast.cc b/gcc/rust/ast/rust-ast.cc
index 2eac09b..14ad3a0 100644
--- a/gcc/rust/ast/rust-ast.cc
+++ b/gcc/rust/ast/rust-ast.cc
@@ -4228,8 +4228,10 @@ BlockExpr::normalize_tail_expr ()
if (!expr)
{
// HACK: try to turn the last statement into a tail expression
- if (statements.size () && statements.back ()->is_expr ())
+ if (!statements.empty () && statements.back ()->is_expr ())
{
+ // Watch out: This reference become invalid when the vector is
+ // modified.
auto &stmt = static_cast<ExprStmt &> (*statements.back ());
if (!stmt.is_semicolon_followed ())
diff --git a/gcc/rust/expand/rust-expand-visitor.cc b/gcc/rust/expand/rust-expand-visitor.cc
index 28ff3df..055f723 100644
--- a/gcc/rust/expand/rust-expand-visitor.cc
+++ b/gcc/rust/expand/rust-expand-visitor.cc
@@ -149,12 +149,18 @@ expand_item_attribute (AST::Item &item, AST::SimplePath &name,
return result;
}
+/* Helper function to expand a given attribute on a statement and collect back
+ * statements.
+ * T should be anything that can be used as a statement accepting outer
+ * attributes.
+ */
template <typename T>
static std::vector<std::unique_ptr<AST::Stmt>>
-expand_stmt_attribute (T &item, AST::SimplePath &name, MacroExpander &expander)
+expand_stmt_attribute (T &statement, AST::SimplePath &attribute,
+ MacroExpander &expander)
{
std::vector<std::unique_ptr<AST::Stmt>> result;
- auto frag = expander.expand_attribute_proc_macro (item, name);
+ auto frag = expander.expand_attribute_proc_macro (statement, attribute);
if (!frag.is_error ())
{
for (auto &node : frag.get_nodes ())