From b4b3e86c47f4d4baac1ad20aefb067fd34f394c8 Mon Sep 17 00:00:00 2001 From: Alastair Robertson Date: Tue, 18 Jul 2023 05:10:44 -0700 Subject: [PATCH] TypeGraphParser: Fix lifetimes of ContainerInfo objects Containers store references to ContainerInfos, so the ContainerInfos must live beyond the stack they were created on. Use static variables for simplicity. --- test/TypeGraphParser.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/TypeGraphParser.cpp b/test/TypeGraphParser.cpp index 9260b6f..c9a78b1 100644 --- a/test/TypeGraphParser.cpp +++ b/test/TypeGraphParser.cpp @@ -53,23 +53,23 @@ Primitive::Kind getKind(std::string_view kindStr) { std::string{kindStr}}; } -ContainerInfo getContainerInfo(std::string_view name) { +ContainerInfo& getContainerInfo(std::string_view name) { if (name == "std::vector") { - ContainerInfo info{"std::vector", SEQ_TYPE, "vector"}; + static ContainerInfo info{"std::vector", SEQ_TYPE, "vector"}; info.stubTemplateParams = {1}; return info; } if (name == "std::map") { - ContainerInfo info{"std::map", STD_MAP_TYPE, "utility"}; + static ContainerInfo info{"std::map", STD_MAP_TYPE, "utility"}; info.stubTemplateParams = {2, 3}; return info; } if (name == "std::pair") { - ContainerInfo info{"std::pair", SEQ_TYPE, "utility"}; + static ContainerInfo info{"std::pair", SEQ_TYPE, "utility"}; return info; } if (name == "std::allocator") { - ContainerInfo info{"std::allocator", DUMMY_TYPE, "memory"}; + static ContainerInfo info{"std::allocator", DUMMY_TYPE, "memory"}; return info; } throw TypeGraphParserError{"Unsupported container: " + std::string{name}}; @@ -242,7 +242,7 @@ Type& TypeGraphParser::parseType(std::string_view& input, size_t rootIndent) { auto nameEndPos = line.find('(', nameStartPos + 1); auto name = line.substr(nameStartPos, nameEndPos - nameStartPos - 1); - auto info = getContainerInfo(name); + auto& info = getContainerInfo(name); auto size = parseIntAttribute(line, nodeTypeName, "size: ");