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 ())
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 ())