diff --git a/libsolidity/ast/AST.h b/libsolidity/ast/AST.h index 5e6829553..8aab10b9a 100644 --- a/libsolidity/ast/AST.h +++ b/libsolidity/ast/AST.h @@ -32,7 +32,6 @@ #include #include #include -#include #include #include diff --git a/libsolidity/ast/ASTJsonImporter.cpp b/libsolidity/ast/ASTJsonImporter.cpp index a7d001d52..07522b841 100644 --- a/libsolidity/ast/ASTJsonImporter.cpp +++ b/libsolidity/ast/ASTJsonImporter.cpp @@ -74,6 +74,7 @@ map> ASTJsonImporter::jsonToSourceUnit(map ASTPointer ASTJsonImporter::createASTNode(Json const& _node, Args&&... _args) { + static_assert(sizeof(Json::number_integer_t) == sizeof(uint64_t)); astAssert(member(_node, "id").is_number_integer(), "'id'-field must be 64bit integer."); int64_t id = static_cast(_node["id"]); diff --git a/libsolidity/interface/StandardCompiler.cpp b/libsolidity/interface/StandardCompiler.cpp index 75fd0ad46..34232e359 100644 --- a/libsolidity/interface/StandardCompiler.cpp +++ b/libsolidity/interface/StandardCompiler.cpp @@ -388,7 +388,7 @@ Json collectEVMObject( function const& _artifactRequested ) { - Json output = Json::object(); + Json output{Json::object()}; if (_artifactRequested("object")) output["object"] = _object.toHex(); if (_artifactRequested("opcodes")) @@ -1562,6 +1562,7 @@ Json StandardCompiler::formatFunctionDebugData( map const& _debugInfo ) { + static_assert(is_same_v); Json ret{Json::object()}; for (auto const& [name, info]: _debugInfo) { diff --git a/libsolidity/interface/StorageLayout.cpp b/libsolidity/interface/StorageLayout.cpp index cae0d96f7..b81f06cf3 100644 --- a/libsolidity/interface/StorageLayout.cpp +++ b/libsolidity/interface/StorageLayout.cpp @@ -39,7 +39,7 @@ Json StorageLayout::generate(ContractDefinition const& _contractDef) for (auto [var, slot, offset]: contractType->stateVariables()) variables.emplace_back(generate(*var, slot, offset)); - Json layout; + Json layout(Json::object()); layout["storage"] = std::move(variables); layout["types"] = std::move(m_types); return layout; @@ -47,7 +47,7 @@ Json StorageLayout::generate(ContractDefinition const& _contractDef) Json StorageLayout::generate(VariableDeclaration const& _var, u256 const& _slot, unsigned _offset) { - Json varEntry; + Json varEntry(Json::object()); Type const* varType = _var.type(); varEntry["label"] = _var.name(); diff --git a/libsolidity/lsp/LanguageServer.cpp b/libsolidity/lsp/LanguageServer.cpp index 19e77e8e9..822f5930e 100644 --- a/libsolidity/lsp/LanguageServer.cpp +++ b/libsolidity/lsp/LanguageServer.cpp @@ -88,12 +88,12 @@ int toDiagnosticSeverity(Error::Type _errorType) Json semanticTokensLegend() { - Json legend = Json::object(); + Json legend{Json::object()}; // NOTE! The (alphabetical) order and items must match exactly the items of // their respective enum class members. - Json tokenTypes = Json::array(); + Json tokenTypes{Json::array()}; tokenTypes.emplace_back("class"); tokenTypes.emplace_back("comment"); tokenTypes.emplace_back("enum"); @@ -116,7 +116,7 @@ Json semanticTokensLegend() tokenTypes.emplace_back("variable"); legend["tokenTypes"] = tokenTypes; - Json tokenModifiers = Json::array(); + Json tokenModifiers{Json::array()}; tokenModifiers.emplace_back("abstract"); tokenModifiers.emplace_back("declaration"); tokenModifiers.emplace_back("definition"); @@ -284,7 +284,7 @@ void LanguageServer::compileAndUpdateDiagnostics() // LSP only has diagnostics applied to individual files. continue; - Json jsonDiag; + Json jsonDiag{Json::object()}; jsonDiag["source"] = "solc"; jsonDiag["severity"] = toDiagnosticSeverity(error->type()); jsonDiag["code"] = Json{error->errorId().error}; @@ -297,7 +297,7 @@ void LanguageServer::compileAndUpdateDiagnostics() if (auto const* secondary = error->secondarySourceLocation()) for (auto&& [secondaryMessage, secondaryLocation]: secondary->infos) { - Json jsonRelated; + Json jsonRelated{Json::object()}; jsonRelated["message"] = secondaryMessage; jsonRelated["location"] = toJson(secondaryLocation); jsonDiag["relatedInformation"].emplace_back(jsonRelated); @@ -308,7 +308,7 @@ void LanguageServer::compileAndUpdateDiagnostics() if (m_client.traceValue() != TraceValue::Off) { - Json extra; + Json extra{Json::object()}; extra["openFileCount"] = Json{diagnosticsBySourceUnit.size()}; m_client.trace("Number of currently open files: " + to_string(diagnosticsBySourceUnit.size()), extra); } @@ -316,7 +316,7 @@ void LanguageServer::compileAndUpdateDiagnostics() m_nonemptyDiagnostics.clear(); for (auto&& [sourceUnitName, diagnostics]: diagnosticsBySourceUnit) { - Json params; + Json params{Json::object()}; params["uri"] = m_fileRepository.sourceUnitNameToUri(sourceUnitName); if (!diagnostics.empty()) m_nonemptyDiagnostics.insert(sourceUnitName); @@ -408,7 +408,7 @@ void LanguageServer::handleInitialize(MessageID _id, Json const& _args) if (_args["initializationOptions"].is_object()) changeConfiguration(_args["initializationOptions"]); - Json replyArgs; + Json replyArgs{Json::object()}; replyArgs["serverInfo"]["name"] = "solc"; replyArgs["serverInfo"]["version"] = string(VersionNumber); replyArgs["capabilities"]["definitionProvider"] = true; @@ -441,7 +441,7 @@ void LanguageServer::semanticTokensFull(MessageID _id, Json const& _args) m_compilerStack.charStream(sourceName); Json data = SemanticTokensBuilder().build(ast, m_compilerStack.charStream(sourceName)); - Json reply = Json::object(); + Json reply{Json::object()}; reply["data"] = data; m_client.reply(_id, std::move(reply)); diff --git a/libsolidity/lsp/RenameSymbol.cpp b/libsolidity/lsp/RenameSymbol.cpp index 4934ea37e..f63877876 100644 --- a/libsolidity/lsp/RenameSymbol.cpp +++ b/libsolidity/lsp/RenameSymbol.cpp @@ -91,10 +91,10 @@ void RenameSymbol::operator()(MessageID _id, Json const& _args) // Apply changes in reverse order (will iterate in reverse) sort(m_locations.begin(), m_locations.end()); - Json reply = Json::object(); + Json reply{Json::object()}; reply["changes"] = Json::object(); - Json edits = Json::array(); + Json edits{Json::array()}; for (auto i = m_locations.rbegin(); i != m_locations.rend(); i++) { @@ -106,7 +106,7 @@ void RenameSymbol::operator()(MessageID _id, Json const& _args) buffer.replace((size_t)i->start, (size_t)(i->end - i->start), newName); fileRepository().setSourceByUri(uri, std::move(buffer)); - Json edit = Json::object(); + Json edit{Json::object()}; edit["range"] = toRange(*i); edit["newText"] = newName; @@ -115,7 +115,7 @@ void RenameSymbol::operator()(MessageID _id, Json const& _args) if (i + 1 == m_locations.rend() || (i + 1)->sourceName != i->sourceName) { reply["changes"][uri] = edits; - edits = Json::array(); + edits = Json::array(); // Reset. } } diff --git a/libsolidity/lsp/Transport.cpp b/libsolidity/lsp/Transport.cpp index 13af12147..c9ff68623 100644 --- a/libsolidity/lsp/Transport.cpp +++ b/libsolidity/lsp/Transport.cpp @@ -106,7 +106,7 @@ optional> Transport::parseHeaders() void Transport::notify(string _method, Json _message) { - Json json; + Json json{Json::object()}; json["method"] = std::move(_method); json["params"] = std::move(_message); send(std::move(json)); @@ -114,14 +114,14 @@ void Transport::notify(string _method, Json _message) void Transport::reply(MessageID _id, Json _message) { - Json json; + Json json{Json::object()}; json["result"] = std::move(_message); send(std::move(json), _id); } void Transport::error(MessageID _id, ErrorCode _code, string _message) { - Json json; + Json json{Json::object()}; json["error"]["code"] = static_cast(_code); json["error"]["message"] = std::move(_message); send(std::move(json), _id);