Today I found out that std::move() on a stack object made raw pointers dangle.
Called here:
for (auto thread_tuple : db->queryRows<std::tuple<int, int, std::string, std::string>>("SELECT id, permission_object_id, slug, title FROM board")) {
// Board board(this, db, std::get<0>(thread_tuple), std::get<1>(thread_tuple), std::get<2>(thread_tuple), std::get<3>(thread_tuple));
auto board = std::make_unique<Board>(this, db, std::get<0>(thread_tuple), std::get<1>(thread_tuple), std::get<2>(thread_tuple), std::get<3>(thread_tuple));
std::print("{}, ", board->getId());
board->cacheAllThreads();
this->slug_to_board_id.emplace(std::get<2>(thread_tuple), board->getId());
this->boards.insert(std::make_pair(board->getId(), std::move(board)));
}
Issue resolved by storing in heap with unique_ptr:
// std::unordered_map<int, Board> boards;
std::unordered_map<int, std::unique_ptr<Board>> boards;