From 77afe4463139538914bfafda6d9920fc61dab673 Mon Sep 17 00:00:00 2001 From: Lai-YT <381xvmvbib@gmail.com> Date: Wed, 10 Jul 2024 14:10:37 +0800 Subject: [PATCH] Fix use-after-move --- parser.y | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/parser.y b/parser.y index f351d19b..75ea12f6 100644 --- a/parser.y +++ b/parser.y @@ -423,15 +423,15 @@ decl: declaration_specifiers init_declarator_list_opt SEMICOLON { // A record declaration that doesn't declare any identifier, e.g., `struct point {int x, int y};`. if (init_decl_list.empty()) { decl_list.push_back(std::move(decl)); - } - - auto& rec_decl = dynamic_cast(*decl); - // Initialize record variable. - for (auto& init_decl : init_decl_list) { - if (init_decl) { - init_decl->type = ResolveType(rec_decl.type->Clone(), std::move(init_decl->type)); + } else { + auto& rec_decl = dynamic_cast(*decl); + // Initialize record variable. + for (auto& init_decl : init_decl_list) { + if (init_decl) { + init_decl->type = ResolveType(rec_decl.type->Clone(), std::move(init_decl->type)); + } + decl_list.push_back(std::move(init_decl)); } - decl_list.push_back(std::move(init_decl)); } } $$ = std::make_unique(Loc(@1), std::move(decl_list));