From e4a35098456bc457a79f0d6b5527d9d30a696262 Mon Sep 17 00:00:00 2001 From: ISSOtm Date: Fri, 15 Mar 2024 21:39:50 +0100 Subject: [PATCH] Fix build failure with GCC 13 It complains about *those* calls returning a dangling reference... Unfortunately, GCC does not provide more information about what the reference *is*. (It only mentions the temporary being destroyed at the end of this *huge* expression.) I am normally not one to just commit a thing that gets rid of a warning if I can't explain why, but this eludes me. Stubbing out the calls to only return a captured variable still complains, which led me to test that the error wasn't stemming from the `Visitor` itself... which it seems to? But I don't see why a reference to the *visitor* should be kept... Anyway, here is the obligatory part where I state my yearning for Rust :) --- src/asm/fstack.cpp | 5 +++-- src/link/main.cpp | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/asm/fstack.cpp b/src/asm/fstack.cpp index a1539ede..41ac3aa2 100644 --- a/src/asm/fstack.cpp +++ b/src/asm/fstack.cpp @@ -62,7 +62,7 @@ std::string const &FileStackNode::name() const { } std::string const &FileStackNode::dump(uint32_t curLineNo) const { - std::string const &topName = std::visit(Visitor{ + Visitor visitor{ [this](std::vector const &iters) -> std::string const & { assert(this->parent); // REPT nodes use their parent's name std::string const &lastName = this->parent->dump(this->lineNo); @@ -80,7 +80,8 @@ std::string const &FileStackNode::dump(uint32_t curLineNo) const { } return name; }, - }, data); + }; + std::string const &topName = std::visit(visitor, data); fprintf(stderr, "(%" PRIu32 ")", curLineNo); return topName; } diff --git a/src/link/main.cpp b/src/link/main.cpp index e164db3f..ceaa6bf5 100644 --- a/src/link/main.cpp +++ b/src/link/main.cpp @@ -66,7 +66,7 @@ std::string const &FileStackNode::name() const { } std::string const &FileStackNode::dump(uint32_t curLineNo) const { - std::string const &topName = std::visit(Visitor{ + Visitor visitor{ [this](std::vector const &iters) -> std::string const & { assert(this->parent); // REPT nodes use their parent's name std::string const &lastName = this->parent->dump(this->lineNo); @@ -87,7 +87,8 @@ std::string const &FileStackNode::dump(uint32_t curLineNo) const { [](std::monostate) -> std::string const & { unreachable_(); // This should not be possible }, - }, data); + }; + std::string const &topName = std::visit(visitor, data); fprintf(stderr, "(%" PRIu32 ")", curLineNo); return topName; }