diff --git a/libsolidity/interface/CompilerStack.cpp b/libsolidity/interface/CompilerStack.cpp index 558c262d0..a8a415d99 100644 --- a/libsolidity/interface/CompilerStack.cpp +++ b/libsolidity/interface/CompilerStack.cpp @@ -582,9 +582,9 @@ string const* CompilerStack::sourceMapping(string const& _contractName) const if (!c.sourceMapping) { if (auto items = assemblyItems(_contractName)) - c.sourceMapping = make_unique(evmasm::AssemblyItem::computeSourceMapping(*items, sourceIndices())); + c.sourceMapping.emplace(evmasm::AssemblyItem::computeSourceMapping(*items, sourceIndices())); } - return c.sourceMapping.get(); + return c.sourceMapping ? &*c.sourceMapping : nullptr; } string const* CompilerStack::runtimeSourceMapping(string const& _contractName) const @@ -596,11 +596,11 @@ string const* CompilerStack::runtimeSourceMapping(string const& _contractName) c if (!c.runtimeSourceMapping) { if (auto items = runtimeAssemblyItems(_contractName)) - c.runtimeSourceMapping = make_unique( + c.runtimeSourceMapping.emplace( evmasm::AssemblyItem::computeSourceMapping(*items, sourceIndices()) ); } - return c.runtimeSourceMapping.get(); + return c.runtimeSourceMapping ? &*c.runtimeSourceMapping : nullptr; } std::string const CompilerStack::filesystemFriendlyName(string const& _contractName) const diff --git a/libsolidity/interface/CompilerStack.h b/libsolidity/interface/CompilerStack.h index 96dbc4f04..d3fe1a45a 100644 --- a/libsolidity/interface/CompilerStack.h +++ b/libsolidity/interface/CompilerStack.h @@ -348,8 +348,8 @@ private: util::LazyInit storageLayout; util::LazyInit userDocumentation; util::LazyInit devDocumentation; - mutable std::unique_ptr sourceMapping; - mutable std::unique_ptr runtimeSourceMapping; + mutable std::optional sourceMapping; + mutable std::optional runtimeSourceMapping; }; /// Loads the missing sources from @a _ast (named @a _path) using the callback diff --git a/libyul/backends/wasm/WasmAST.h b/libyul/backends/wasm/WasmAST.h index 02862aea2..635b7c4ea 100644 --- a/libyul/backends/wasm/WasmAST.h +++ b/libyul/backends/wasm/WasmAST.h @@ -25,6 +25,7 @@ #include #include #include +#include namespace solidity::yul::wasm { @@ -76,7 +77,7 @@ struct FunctionImport { std::string externalName; std::string internalName; std::vector paramTypes; - std::unique_ptr returnType; + std::optional returnType; }; struct FunctionDefinition diff --git a/libyul/backends/wasm/WasmCodeTransform.cpp b/libyul/backends/wasm/WasmCodeTransform.cpp index 297133107..f2e624552 100644 --- a/libyul/backends/wasm/WasmCodeTransform.cpp +++ b/libyul/backends/wasm/WasmCodeTransform.cpp @@ -29,6 +29,8 @@ #include +#include + using namespace std; using namespace solidity; using namespace solidity::yul; @@ -125,7 +127,7 @@ wasm::Expression WasmCodeTransform::operator()(FunctionCall const& _call) builtin->name.str().substr(4), builtin->name.str(), {}, - builtin->returns.empty() ? nullptr : make_unique(builtin->returns.front().str()) + builtin->returns.empty() ? nullopt : make_optional(builtin->returns.front().str()) }; for (auto const& param: builtin->parameters) imp.paramTypes.emplace_back(param.str()); diff --git a/test/boostTest.cpp b/test/boostTest.cpp index eb55ead89..5b45cc758 100644 --- a/test/boostTest.cpp +++ b/test/boostTest.cpp @@ -89,7 +89,10 @@ int registerTests( } else { - static vector> filenames; + // This must be a vector of unique_ptrs because Boost.Test keeps the equivalent of a string_view to the filename + // that is passed in. If the strings were stored directly in the vector, pointers/references to them would be + // invalidated on reallocation. + static vector> filenames; filenames.emplace_back(make_unique(_path.string())); _suite.add(make_test_case(