Skip to content

Commit

Permalink
Fix returning reference to local object. (#1102)
Browse files Browse the repository at this point in the history
  • Loading branch information
1uc authored Dec 5, 2023
1 parent 03b7485 commit 474c3fe
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/language/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ def _is_member_type_wrapped_as_shared_pointer(self):
def member_rvalue_typename(self):
"""returns rvalue reference type when used as returned or parameter type"""
typename = self.member_typename
if not self.is_integral_type_node:
if not self.is_integral_type_node and not self._is_member_type_wrapped_as_shared_pointer:
return "const " + typename + "&"
return typename

Expand Down
2 changes: 1 addition & 1 deletion src/language/templates/ast/ast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ std::string Ast::get_node_name() const {
throw std::logic_error("get_node_name() not implemented");
}

const std::shared_ptr<StatementBlock>& Ast::get_statement_block() const {
std::shared_ptr<StatementBlock> Ast::get_statement_block() const {
throw std::runtime_error("get_statement_block not implemented");
}

Expand Down
2 changes: 1 addition & 1 deletion src/language/templates/ast/ast.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ struct Ast: public std::enable_shared_from_this<Ast> {
*
* \sa ast::StatementBlock
*/
virtual const std::shared_ptr<StatementBlock>& get_statement_block() const;
virtual std::shared_ptr<StatementBlock> get_statement_block() const;

/**
* \brief Set symbol table for the AST node
Expand Down
4 changes: 2 additions & 2 deletions src/language/templates/pybind/pyast.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ struct PyAst: public Ast {
PYBIND11_OVERRIDE(symtab::SymbolTable*, Ast, get_symbol_table, );
}

const std::shared_ptr<StatementBlock>& get_statement_block() const override {
PYBIND11_OVERRIDE(const std::shared_ptr<StatementBlock>&, Ast, get_statement_block, );
std::shared_ptr<StatementBlock> get_statement_block() const override {
PYBIND11_OVERRIDE(std::shared_ptr<StatementBlock>, Ast, get_statement_block, );
}

void set_symbol_table(symtab::SymbolTable* newsymtab) override {
Expand Down

0 comments on commit 474c3fe

Please sign in to comment.