From d048b633dd02014f8bff1b512ce4d5ae2b8b7903 Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Fri, 25 Sep 2026 10:59:05 +0200 Subject: Fix move related memory leaks in AST helpers --- include/elna/boot/ast.h | 43 ++++++++++++++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 11 deletions(-) (limited to 'include') diff --git a/include/elna/boot/ast.h b/include/elna/boot/ast.h index 4a0cdb0..6a3b9c9 100644 --- a/include/elna/boot/ast.h +++ b/include/elna/boot/ast.h @@ -163,15 +163,14 @@ namespace elna::boot /// Scope containing the variables, entered by the name analysis. std::shared_ptr symbols; - block() = default; block(std::vector&& variables, std::vector&& statements); block(const block&) = delete; block(block&& that) noexcept = default; block& operator=(const block&) = delete; - block& operator=(block&& that) noexcept = default; + block& operator=(block&& that) noexcept; - ~block(); + virtual ~block(); }; /** @@ -380,7 +379,7 @@ namespace elna::boot { attribute(identifier&& name, std::vector arguments); attribute(const attribute&) = delete; - attribute(attribute&& that) noexcept; + attribute(attribute&& that) noexcept = default; ~attribute(); attribute& operator=(const attribute& that) = delete; @@ -401,6 +400,11 @@ namespace elna::boot { identifier_definition(const std::string& name, const source_position& position, const bool exported, std::vector&& attributes = std::vector{}); + identifier_definition(const identifier_definition&) = delete; + identifier_definition(identifier_definition&&) noexcept = default; + + identifier_definition& operator=(const identifier_definition&) = delete; + identifier_definition& operator=(identifier_definition&&) noexcept = default; const std::string& name() const; const identifier& id() const; @@ -688,9 +692,12 @@ namespace elna::boot expression *return_expression{ nullptr }; explicit procedure_body(block&& body, expression *return_expression = nullptr); - procedure_body(procedure_body&& that) noexcept = default; + procedure_body(const procedure_body&) = delete; + procedure_body(procedure_body&& that) noexcept; + ~procedure_body() override; - virtual ~procedure_body() = default; + procedure_body& operator=(const procedure_body&) = delete; + procedure_body& operator=(procedure_body&& that) noexcept; }; void traverse_body(parser_visitor *visitor, const procedure_body& body); @@ -791,16 +798,30 @@ namespace elna::boot block body; conditional_statements(expression *prerequisite, block&& body); + conditional_statements(const conditional_statements&) = delete; + conditional_statements(conditional_statements&& that) noexcept; + + conditional_statements& operator=(const conditional_statements&) = delete; + conditional_statements& operator=(conditional_statements&& that) noexcept; expression& prerequisite(); - virtual ~conditional_statements(); + ~conditional_statements(); }; struct switch_case { std::vector labels; block body; + + switch_case(std::vector&& labels, block&& body); + switch_case(const switch_case&) = delete; + switch_case(switch_case&& that) noexcept = default; + + switch_case& operator=(const switch_case&) = delete; + switch_case& operator=(switch_case&& that) noexcept; + + ~switch_case(); }; class case_statement : public statement @@ -983,11 +1004,11 @@ namespace elna::boot conditional_statements *m_branch; public: - const std::vector branches; + std::vector branches; block *alternative; if_statement(const source_position position, conditional_statements *branch, - std::vector&& branches, + std::vector&& branches, block *alternative = nullptr); void accept(parser_visitor *visitor) override; @@ -1016,10 +1037,10 @@ namespace elna::boot conditional_statements *m_branch; public: - const std::vector branches; + std::vector branches; while_statement(const source_position position, conditional_statements *branch, - std::vector&& branches); + std::vector&& branches); void accept(parser_visitor *visitor) override; conditional_statements& branch(); -- cgit v1.2.3