diff --git a/CMakeLists.txt b/CMakeLists.txt index aa6afdc1..29e67227 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,7 +16,7 @@ set(CMAKE_CXX_EXTENSIONS OFF) project(loki VERSION "0.0.1" LANGUAGES C CXX) # Compilation flags, some configuration-specific -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -Wall -Wextra -pedantic -fPIC") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -Wall -Wextra -Wuninitialized -pedantic -fPIC") set(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG -fomit-frame-pointer") set(CMAKE_CXX_FLAGS_DEBUG "-O3 -DDEBUG") diff --git a/include/loki/common/pddl/persistent_factory.hpp b/include/loki/common/pddl/persistent_factory.hpp index 87624e67..78810cf0 100644 --- a/include/loki/common/pddl/persistent_factory.hpp +++ b/include/loki/common/pddl/persistent_factory.hpp @@ -68,7 +68,7 @@ class PersistentFactory { /// @brief Returns a pointer to an existing object /// or creates it before if it does not exist.v template - [[nodiscard]] HolderType const* get_or_create(Args&&... args) { + [[nodiscard]] HolderType const* get_or_create(Args... args) { std::lock_guard hold(m_mutex); /* Construct and insert the element in persistent memory. */ size_t identifier = m_count; @@ -76,12 +76,20 @@ class PersistentFactory { assert((identifier == (m_persistent_vector.size()-1)) || (identifier == m_persistent_vector.size())); // Explicitly call the constructor of T to give exclusive access to the factory. - auto element = HolderType(std::move(SubType(identifier, std::forward(args)...))); + auto element = HolderType(std::move(SubType(identifier, args...))); bool overwrite_last_element = (identifier == m_persistent_vector.size() - 1); // The pointer to the location in persistent memory. - const auto* element_ptr = overwrite_last_element - ? &(m_persistent_vector[identifier] = std::move(element)) - : &(m_persistent_vector.push_back(std::move(element))); + const auto* element_ptr = static_cast(nullptr); + if (overwrite_last_element) { + const auto& persistent_element = m_persistent_vector[identifier] = std::move(element); + element_ptr = &persistent_element; + } else { + const auto& persistent_element = m_persistent_vector.push_back(std::move(element)); + element_ptr = &persistent_element; + } + if (!element_ptr) { + throw std::runtime_error("element_ptr is nullptr"); + } assert(element_ptr); /* Test for uniqueness */ auto it = m_uniqueness_set.find(element_ptr); diff --git a/src/domain/pddl/parser/constants.cpp b/src/domain/pddl/parser/constants.cpp index 65563702..01fd7131 100644 --- a/src/domain/pddl/parser/constants.cpp +++ b/src/domain/pddl/parser/constants.cpp @@ -79,8 +79,7 @@ pddl::ObjectList ConstantListVisitor::operator()(const std::vector& n assert(context.scopes.get("object").has_value()); const auto& [type, _position, _error_handler] = context.scopes.get("object").value(); const auto type_list = pddl::TypeList{type}; - const auto constant_list = parse_constant_definitions(name_nodes, type_list, context); - return constant_list; + return parse_constant_definitions(name_nodes, type_list, context); } pddl::ObjectList ConstantListVisitor::operator()(const ast::TypedListOfNamesRecursively& typed_list_of_names_recursively_node) { @@ -88,8 +87,8 @@ pddl::ObjectList ConstantListVisitor::operator()(const ast::TypedListOfNamesRecu throw UndefinedRequirementError(pddl::RequirementEnum::TYPING, context.scopes.get_error_handler()(typed_list_of_names_recursively_node, "")); } context.references.untrack(pddl::RequirementEnum::TYPING); - const auto type_list = boost::apply_visitor(TypeReferenceTypeVisitor(context), - typed_list_of_names_recursively_node.type); + const auto type_list = boost::apply_visitor( + TypeReferenceTypeVisitor(context), typed_list_of_names_recursively_node.type); // TypedListOfNamesRecursively has user defined base types auto constant_list = parse_constant_definitions(typed_list_of_names_recursively_node.names, type_list, context); // Recursively add objects.