From 0bb88dabb7ec5da5dc6e56c68c1c08aafbd76b28 Mon Sep 17 00:00:00 2001 From: chriseth Date: Wed, 27 Nov 2019 17:24:21 +0100 Subject: [PATCH] Restrict usage of plain "new". --- libevmasm/PathGasMeter.cpp | 4 ++-- libsolidity/analysis/ControlFlowBuilder.cpp | 2 +- libsolidity/analysis/NameAndTypeResolver.cpp | 8 ++++---- libsolidity/ast/Types.cpp | 2 +- libsolidity/codegen/ExpressionCompiler.cpp | 2 +- libsolidity/codegen/ExpressionCompiler.h | 2 +- libsolidity/interface/CompilerStack.cpp | 14 +++++++------- libsolidity/parsing/Parser.cpp | 4 ++-- libyul/AsmParser.cpp | 2 +- solc/CommandLineInterface.cpp | 2 +- test/boostTest.cpp | 2 +- test/contracts/AuctionRegistrar.cpp | 2 +- test/contracts/FixedFeeRegistrar.cpp | 2 +- test/contracts/Wallet.cpp | 2 +- test/libsolidity/ABIJsonTest.h | 2 +- test/libsolidity/ASTJSONTest.h | 2 +- test/libyul/EWasmTranslationTest.h | 2 +- test/libyul/FunctionSideEffects.h | 2 +- test/libyul/ObjectCompilerTest.h | 2 +- test/libyul/YulInterpreterTest.h | 2 +- test/libyul/YulOptimizerTest.cpp | 6 +++++- test/libyul/YulOptimizerTest.h | 2 +- 22 files changed, 37 insertions(+), 33 deletions(-) diff --git a/libevmasm/PathGasMeter.cpp b/libevmasm/PathGasMeter.cpp index 761defdc5..9d14ac947 100644 --- a/libevmasm/PathGasMeter.cpp +++ b/libevmasm/PathGasMeter.cpp @@ -40,7 +40,7 @@ GasMeter::GasConsumption PathGasMeter::estimateMax( shared_ptr const& _state ) { - auto path = unique_ptr(new GasPath()); + auto path = make_unique(); path->index = _startIndex; path->state = _state->copy(); queue(move(path)); @@ -120,7 +120,7 @@ GasMeter::GasConsumption PathGasMeter::handleQueueItem() for (u256 const& tag: jumpTags) { - auto newPath = unique_ptr(new GasPath()); + auto newPath = make_unique(); newPath->index = m_items.size(); if (m_tagPositions.count(tag)) newPath->index = m_tagPositions.at(tag); diff --git a/libsolidity/analysis/ControlFlowBuilder.cpp b/libsolidity/analysis/ControlFlowBuilder.cpp index 6bafc4caa..37d8c824f 100644 --- a/libsolidity/analysis/ControlFlowBuilder.cpp +++ b/libsolidity/analysis/ControlFlowBuilder.cpp @@ -35,7 +35,7 @@ unique_ptr ControlFlowBuilder::createFunctionFlow( FunctionDefinition const& _function ) { - auto functionFlow = unique_ptr(new FunctionFlow()); + auto functionFlow = make_unique(); functionFlow->entry = _nodeContainer.newNode(); functionFlow->exit = _nodeContainer.newNode(); functionFlow->revert = _nodeContainer.newNode(); diff --git a/libsolidity/analysis/NameAndTypeResolver.cpp b/libsolidity/analysis/NameAndTypeResolver.cpp index cc28220ca..008e37bdb 100644 --- a/libsolidity/analysis/NameAndTypeResolver.cpp +++ b/libsolidity/analysis/NameAndTypeResolver.cpp @@ -48,7 +48,7 @@ NameAndTypeResolver::NameAndTypeResolver( m_globalContext(_globalContext) { if (!m_scopes[nullptr]) - m_scopes[nullptr].reset(new DeclarationContainer()); + m_scopes[nullptr] = make_shared(); for (Declaration const* declaration: _globalContext.declarations()) { solAssert(m_scopes[nullptr]->registerDeclaration(*declaration), "Unable to register global declaration."); @@ -545,7 +545,7 @@ bool DeclarationRegistrationHelper::visit(SourceUnit& _sourceUnit) { if (!m_scopes[&_sourceUnit]) // By importing, it is possible that the container already exists. - m_scopes[&_sourceUnit].reset(new DeclarationContainer(m_currentScope, m_scopes[m_currentScope].get())); + m_scopes[&_sourceUnit] = make_shared(m_currentScope, m_scopes[m_currentScope].get()); m_currentScope = &_sourceUnit; return true; } @@ -561,7 +561,7 @@ bool DeclarationRegistrationHelper::visit(ImportDirective& _import) SourceUnit const* importee = _import.annotation().sourceUnit; solAssert(!!importee, ""); if (!m_scopes[importee]) - m_scopes[importee].reset(new DeclarationContainer(nullptr, m_scopes[nullptr].get())); + m_scopes[importee] = make_shared(nullptr, m_scopes[nullptr].get()); m_scopes[&_import] = m_scopes[importee]; registerDeclaration(_import, false); return true; @@ -705,7 +705,7 @@ void DeclarationRegistrationHelper::enterNewSubScope(ASTNode& _subScope) { map>::iterator iter; bool newlyAdded; - shared_ptr container(new DeclarationContainer(m_currentScope, m_scopes[m_currentScope].get())); + shared_ptr container{make_shared(m_currentScope, m_scopes[m_currentScope].get())}; tie(iter, newlyAdded) = m_scopes.emplace(&_subScope, move(container)); solAssert(newlyAdded, "Unable to add new scope."); m_currentScope = &_subScope; diff --git a/libsolidity/ast/Types.cpp b/libsolidity/ast/Types.cpp index ab0d492d4..d1c579d2b 100644 --- a/libsolidity/ast/Types.cpp +++ b/libsolidity/ast/Types.cpp @@ -329,7 +329,7 @@ MemberList const& Type::members(ContractDefinition const* _currentScope) const MemberList::MemberMap members = nativeMembers(_currentScope); if (_currentScope) members += boundFunctions(*this, *_currentScope); - m_members[_currentScope] = unique_ptr(new MemberList(move(members))); + m_members[_currentScope] = make_unique(move(members)); } return *m_members[_currentScope]; } diff --git a/libsolidity/codegen/ExpressionCompiler.cpp b/libsolidity/codegen/ExpressionCompiler.cpp index 62ae2dd63..9a7b45412 100644 --- a/libsolidity/codegen/ExpressionCompiler.cpp +++ b/libsolidity/codegen/ExpressionCompiler.cpp @@ -345,7 +345,7 @@ bool ExpressionCompiler::visit(TupleExpression const& _tuple) if (_tuple.components().size() == 1) m_currentLValue = move(lvalues[0]); else - m_currentLValue.reset(new TupleObject(m_context, move(lvalues))); + m_currentLValue = make_unique(m_context, move(lvalues)); } } return false; diff --git a/libsolidity/codegen/ExpressionCompiler.h b/libsolidity/codegen/ExpressionCompiler.h index 645d67067..07754dedc 100644 --- a/libsolidity/codegen/ExpressionCompiler.h +++ b/libsolidity/codegen/ExpressionCompiler.h @@ -136,7 +136,7 @@ template void ExpressionCompiler::setLValue(Expression const& _expression, _Arguments const&... _arguments) { solAssert(!m_currentLValue, "Current LValue not reset before trying to set new one."); - std::unique_ptr<_LValueType> lvalue(new _LValueType(m_context, _arguments...)); + std::unique_ptr<_LValueType> lvalue = std::make_unique<_LValueType>(m_context, _arguments...); if (_expression.annotation().lValueRequested) m_currentLValue = move(lvalue); else diff --git a/libsolidity/interface/CompilerStack.cpp b/libsolidity/interface/CompilerStack.cpp index 423cdcceb..55640b482 100644 --- a/libsolidity/interface/CompilerStack.cpp +++ b/libsolidity/interface/CompilerStack.cpp @@ -512,7 +512,7 @@ string const* CompilerStack::sourceMapping(string const& _contractName) const if (!c.sourceMapping) { if (auto items = assemblyItems(_contractName)) - c.sourceMapping.reset(new string(computeSourceMapping(*items))); + c.sourceMapping = make_unique(computeSourceMapping(*items)); } return c.sourceMapping.get(); } @@ -526,7 +526,7 @@ string const* CompilerStack::runtimeSourceMapping(string const& _contractName) c if (!c.runtimeSourceMapping) { if (auto items = runtimeAssemblyItems(_contractName)) - c.runtimeSourceMapping.reset(new string(computeSourceMapping(*items))); + c.runtimeSourceMapping = make_unique(computeSourceMapping(*items)); } return c.runtimeSourceMapping.get(); } @@ -663,7 +663,7 @@ Json::Value const& CompilerStack::contractABI(Contract const& _contract) const // caches the result if (!_contract.abi) - _contract.abi.reset(new Json::Value(ABI::generate(*_contract.contract))); + _contract.abi = make_unique(ABI::generate(*_contract.contract)); return *_contract.abi; } @@ -685,7 +685,7 @@ Json::Value const& CompilerStack::storageLayout(Contract const& _contract) const // caches the result if (!_contract.storageLayout) - _contract.storageLayout.reset(new Json::Value(StorageLayout().generate(*_contract.contract))); + _contract.storageLayout = make_unique(StorageLayout().generate(*_contract.contract)); return *_contract.storageLayout; } @@ -707,7 +707,7 @@ Json::Value const& CompilerStack::natspecUser(Contract const& _contract) const // caches the result if (!_contract.userDocumentation) - _contract.userDocumentation.reset(new Json::Value(Natspec::userDocumentation(*_contract.contract))); + _contract.userDocumentation = make_unique(Natspec::userDocumentation(*_contract.contract)); return *_contract.userDocumentation; } @@ -729,7 +729,7 @@ Json::Value const& CompilerStack::natspecDev(Contract const& _contract) const // caches the result if (!_contract.devDocumentation) - _contract.devDocumentation.reset(new Json::Value(Natspec::devDocumentation(*_contract.contract))); + _contract.devDocumentation = make_unique(Natspec::devDocumentation(*_contract.contract)); return *_contract.devDocumentation; } @@ -762,7 +762,7 @@ string const& CompilerStack::metadata(Contract const& _contract) const // cache the result if (!_contract.metadata) - _contract.metadata.reset(new string(createMetadata(_contract))); + _contract.metadata = make_unique(createMetadata(_contract)); return *_contract.metadata; } diff --git a/libsolidity/parsing/Parser.cpp b/libsolidity/parsing/Parser.cpp index ff00df90b..07f0ef5f7 100644 --- a/libsolidity/parsing/Parser.cpp +++ b/libsolidity/parsing/Parser.cpp @@ -350,7 +350,7 @@ ASTPointer Parser::parseInheritanceSpecifier() if (m_scanner->currentToken() == Token::LParen) { m_scanner->next(); - arguments.reset(new vector>(parseFunctionCallListArguments())); + arguments = make_unique>>(parseFunctionCallListArguments()); nodeFactory.markEndPosition(); expectToken(Token::RParen); } @@ -811,7 +811,7 @@ ASTPointer Parser::parseModifierInvocation() if (m_scanner->currentToken() == Token::LParen) { m_scanner->next(); - arguments.reset(new vector>(parseFunctionCallListArguments())); + arguments = make_unique>>(parseFunctionCallListArguments()); nodeFactory.markEndPosition(); expectToken(Token::RParen); } diff --git a/libyul/AsmParser.cpp b/libyul/AsmParser.cpp index 75e488290..de98f7d11 100644 --- a/libyul/AsmParser.cpp +++ b/libyul/AsmParser.cpp @@ -217,7 +217,7 @@ Statement Parser::parseStatement() expectToken(Token::AssemblyAssign); - assignment.value.reset(new Expression(parseExpression())); + assignment.value = make_unique(parseExpression()); assignment.location.end = locationOf(*assignment.value).end; return Statement{std::move(assignment)}; diff --git a/solc/CommandLineInterface.cpp b/solc/CommandLineInterface.cpp index f85b8c3f9..b37507076 100644 --- a/solc/CommandLineInterface.cpp +++ b/solc/CommandLineInterface.cpp @@ -933,7 +933,7 @@ bool CommandLineInterface::processInput() return link(); } - m_compiler.reset(new CompilerStack(fileReader)); + m_compiler = make_unique(fileReader); unique_ptr formatter; if (m_args.count(g_argNewReporter)) diff --git a/test/boostTest.cpp b/test/boostTest.cpp index fd33f667e..27db38486 100644 --- a/test/boostTest.cpp +++ b/test/boostTest.cpp @@ -96,7 +96,7 @@ int registerTests( { static vector> filenames; - filenames.emplace_back(new string(_path.string())); + filenames.emplace_back(make_unique(_path.string())); _suite.add(make_test_case( [config, _testCaseCreator] { diff --git a/test/contracts/AuctionRegistrar.cpp b/test/contracts/AuctionRegistrar.cpp index b643754e9..183cbdf98 100644 --- a/test/contracts/AuctionRegistrar.cpp +++ b/test/contracts/AuctionRegistrar.cpp @@ -223,7 +223,7 @@ protected: void deployRegistrar() { if (!s_compiledRegistrar) - s_compiledRegistrar.reset(new bytes(compileContract(registrarCode, "GlobalRegistrar"))); + s_compiledRegistrar = make_unique(compileContract(registrarCode, "GlobalRegistrar")); sendMessage(*s_compiledRegistrar, true); BOOST_REQUIRE(m_transactionSuccessful); diff --git a/test/contracts/FixedFeeRegistrar.cpp b/test/contracts/FixedFeeRegistrar.cpp index e82f389fc..d26cc94a9 100644 --- a/test/contracts/FixedFeeRegistrar.cpp +++ b/test/contracts/FixedFeeRegistrar.cpp @@ -132,7 +132,7 @@ protected: void deployRegistrar() { if (!s_compiledRegistrar) - s_compiledRegistrar.reset(new bytes(compileContract(registrarCode, "FixedFeeRegistrar"))); + s_compiledRegistrar = make_unique(compileContract(registrarCode, "FixedFeeRegistrar")); sendMessage(*s_compiledRegistrar, true); BOOST_REQUIRE(m_transactionSuccessful); diff --git a/test/contracts/Wallet.cpp b/test/contracts/Wallet.cpp index d0cbb9956..f9d3b0f0a 100644 --- a/test/contracts/Wallet.cpp +++ b/test/contracts/Wallet.cpp @@ -448,7 +448,7 @@ protected: ) { if (!s_compiledWallet) - s_compiledWallet.reset(new bytes(compileContract(walletCode, "Wallet"))); + s_compiledWallet = make_unique(compileContract(walletCode, "Wallet")); bytes args = encodeArgs(u256(0x60), _required, _dailyLimit, u256(_owners.size()), _owners); sendMessage(*s_compiledWallet + args, true, _value); diff --git a/test/libsolidity/ABIJsonTest.h b/test/libsolidity/ABIJsonTest.h index e7be7947f..82a19da3f 100644 --- a/test/libsolidity/ABIJsonTest.h +++ b/test/libsolidity/ABIJsonTest.h @@ -36,7 +36,7 @@ class ABIJsonTest: public TestCase { public: static std::unique_ptr create(Config const& _config) - { return std::unique_ptr(new ABIJsonTest(_config.filename)); } + { return std::make_unique(_config.filename); } ABIJsonTest(std::string const& _filename); TestResult run(std::ostream& _stream, std::string const& _linePrefix = "", bool const _formatted = false) override; diff --git a/test/libsolidity/ASTJSONTest.h b/test/libsolidity/ASTJSONTest.h index dcd385623..cf508e87b 100644 --- a/test/libsolidity/ASTJSONTest.h +++ b/test/libsolidity/ASTJSONTest.h @@ -36,7 +36,7 @@ class ASTJSONTest: public TestCase { public: static std::unique_ptr create(Config const& _config) - { return std::unique_ptr(new ASTJSONTest(_config.filename)); } + { return std::make_unique(_config.filename); } ASTJSONTest(std::string const& _filename); TestResult run(std::ostream& _stream, std::string const& _linePrefix = "", bool const _formatted = false) override; diff --git a/test/libyul/EWasmTranslationTest.h b/test/libyul/EWasmTranslationTest.h index 351f83607..c63c305f9 100644 --- a/test/libyul/EWasmTranslationTest.h +++ b/test/libyul/EWasmTranslationTest.h @@ -37,7 +37,7 @@ class EWasmTranslationTest: public dev::solidity::test::EVMVersionRestrictedTest public: static std::unique_ptr create(Config const& _config) { - return std::unique_ptr(new EWasmTranslationTest(_config.filename)); + return std::make_unique(_config.filename); } explicit EWasmTranslationTest(std::string const& _filename); diff --git a/test/libyul/FunctionSideEffects.h b/test/libyul/FunctionSideEffects.h index 8fad2961c..582b45432 100644 --- a/test/libyul/FunctionSideEffects.h +++ b/test/libyul/FunctionSideEffects.h @@ -34,7 +34,7 @@ class FunctionSideEffects: public dev::solidity::test::TestCase { public: static std::unique_ptr create(Config const& _config) - { return std::unique_ptr(new FunctionSideEffects(_config.filename)); } + { return std::make_unique(_config.filename); } explicit FunctionSideEffects(std::string const& _filename); TestResult run(std::ostream& _stream, std::string const& _linePrefix = "", bool const _formatted = false) override; diff --git a/test/libyul/ObjectCompilerTest.h b/test/libyul/ObjectCompilerTest.h index df7fd0905..6e89e059d 100644 --- a/test/libyul/ObjectCompilerTest.h +++ b/test/libyul/ObjectCompilerTest.h @@ -42,7 +42,7 @@ class ObjectCompilerTest: public dev::solidity::test::TestCase public: static std::unique_ptr create(Config const& _config) { - return std::unique_ptr(new ObjectCompilerTest(_config.filename)); + return std::make_unique(_config.filename); } explicit ObjectCompilerTest(std::string const& _filename); diff --git a/test/libyul/YulInterpreterTest.h b/test/libyul/YulInterpreterTest.h index 4263b7336..eb456f1d0 100644 --- a/test/libyul/YulInterpreterTest.h +++ b/test/libyul/YulInterpreterTest.h @@ -42,7 +42,7 @@ class YulInterpreterTest: public dev::solidity::test::EVMVersionRestrictedTestCa public: static std::unique_ptr create(Config const& _config) { - return std::unique_ptr(new YulInterpreterTest(_config.filename)); + return std::make_unique(_config.filename); } explicit YulInterpreterTest(std::string const& _filename); diff --git a/test/libyul/YulOptimizerTest.cpp b/test/libyul/YulOptimizerTest.cpp index 07dc8a5c3..76e9af3df 100644 --- a/test/libyul/YulOptimizerTest.cpp +++ b/test/libyul/YulOptimizerTest.cpp @@ -424,7 +424,11 @@ void YulOptimizerTest::disambiguate() void YulOptimizerTest::updateContext() { m_nameDispenser = make_unique(*m_dialect, *m_ast, m_reservedIdentifiers); - m_context = unique_ptr(new OptimiserStepContext{*m_dialect, *m_nameDispenser, m_reservedIdentifiers}); + m_context = make_unique(OptimiserStepContext{ + *m_dialect, + *m_nameDispenser, + m_reservedIdentifiers + }); } void YulOptimizerTest::printErrors(ostream& _stream, ErrorList const& _errors) diff --git a/test/libyul/YulOptimizerTest.h b/test/libyul/YulOptimizerTest.h index 87248cfad..a9cc04ab1 100644 --- a/test/libyul/YulOptimizerTest.h +++ b/test/libyul/YulOptimizerTest.h @@ -51,7 +51,7 @@ class YulOptimizerTest: public dev::solidity::test::EVMVersionRestrictedTestCase public: static std::unique_ptr create(Config const& _config) { - return std::unique_ptr(new YulOptimizerTest(_config.filename)); + return std::make_unique(_config.filename); } explicit YulOptimizerTest(std::string const& _filename);