Skip to content

Commit 62fe574

Browse files
author
Christian Parpart
committed
make use of C++ = default constructor declarations as well as more non-static member initialization syntax.
1 parent d10bae2 commit 62fe574

27 files changed

+51
-65
lines changed

libdevcore/IndentedWriter.h

+1-3
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ DEV_SIMPLE_EXCEPTION(IndentedWriterError);
3434
class IndentedWriter
3535
{
3636
public:
37-
explicit IndentedWriter(): m_lines(std::vector<Line>{{std::string(), 0}}) {}
38-
3937
// Returns the formatted output.
4038
std::string format() const;
4139

@@ -61,7 +59,7 @@ class IndentedWriter
6159
unsigned indentation;
6260
};
6361

64-
std::vector<Line> m_lines;
62+
std::vector<Line> m_lines{{std::string(), 0}};
6563
};
6664

6765
}

libevmasm/Assembly.h

-2
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ using AssemblyPointer = std::shared_ptr<Assembly>;
4545
class Assembly
4646
{
4747
public:
48-
Assembly() {}
49-
5048
AssemblyItem newTag() { assertThrow(m_usedTags < 0xffffffff, AssemblyException, ""); return AssemblyItem(Tag, m_usedTags++); }
5149
AssemblyItem newPushTag() { assertThrow(m_usedTags < 0xffffffff, AssemblyException, ""); return AssemblyItem(PushTag, m_usedTags++); }
5250
/// Returns a tag identified by the given name. Creates it if it does not yet exist.

libevmasm/KnownState.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ KnownState::StoreOperation KnownState::storeInStorage(
304304

305305
AssemblyItem item(Instruction::SSTORE, _location);
306306
Id id = m_expressionClasses->find(item, {_slot, _value}, true, m_sequenceNumber);
307-
StoreOperation operation(StoreOperation::Storage, _slot, m_sequenceNumber, id);
307+
StoreOperation operation{StoreOperation::Storage, _slot, m_sequenceNumber, id};
308308
m_storageContent[_slot] = _value;
309309
// increment a second time so that we get unique sequence numbers for writes
310310
m_sequenceNumber++;
@@ -336,7 +336,7 @@ KnownState::StoreOperation KnownState::storeInMemory(Id _slot, Id _value, Source
336336

337337
AssemblyItem item(Instruction::MSTORE, _location);
338338
Id id = m_expressionClasses->find(item, {_slot, _value}, true, m_sequenceNumber);
339-
StoreOperation operation(StoreOperation(StoreOperation::Memory, _slot, m_sequenceNumber, id));
339+
StoreOperation operation{StoreOperation::Memory, _slot, m_sequenceNumber, id};
340340
m_memoryContent[_slot] = _value;
341341
// increment a second time so that we get unique sequence numbers for writes
342342
m_sequenceNumber++;

libevmasm/KnownState.h

+6-11
Original file line numberDiff line numberDiff line change
@@ -74,18 +74,13 @@ class KnownState
7474
struct StoreOperation
7575
{
7676
enum Target { Invalid, Memory, Storage };
77-
StoreOperation(): target(Invalid), sequenceNumber(-1) {}
78-
StoreOperation(
79-
Target _target,
80-
Id _slot,
81-
unsigned _sequenceNumber,
82-
Id _expression
83-
): target(_target), slot(_slot), sequenceNumber(_sequenceNumber), expression(_expression) {}
77+
8478
bool isValid() const { return target != Invalid; }
85-
Target target;
86-
Id slot;
87-
unsigned sequenceNumber;
88-
Id expression;
79+
80+
Target target{Invalid};
81+
Id slot{std::numeric_limits<Id>::max()};
82+
unsigned sequenceNumber{std::numeric_limits<unsigned>::max()};
83+
Id expression{std::numeric_limits<Id>::max()};
8984
};
9085

9186
explicit KnownState(

liblangutil/CharStream.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ namespace langutil
6767
class CharStream
6868
{
6969
public:
70-
CharStream(): m_position(0) {}
70+
CharStream() = default;
7171
explicit CharStream(std::string const& _source, std::string const& name):
72-
m_source(_source), m_name(name), m_position(0) {}
72+
m_source(_source), m_name(name) {}
7373

7474
int position() const { return m_position; }
7575
bool isPastEndOfInput(size_t _charsForward = 0) const { return (m_position + _charsForward) >= m_source.size(); }
@@ -94,7 +94,7 @@ class CharStream
9494
private:
9595
std::string m_source;
9696
std::string m_name;
97-
size_t m_position;
97+
size_t m_position{0};
9898
};
9999

100100
}

liblangutil/EVMVersion.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class EVMVersion:
3939
boost::equality_comparable<EVMVersion>
4040
{
4141
public:
42-
EVMVersion() {}
42+
EVMVersion() = default;
4343

4444
static EVMVersion homestead() { return {Version::Homestead}; }
4545
static EVMVersion tangerineWhistle() { return {Version::TangerineWhistle}; }

liblangutil/SourceReferenceExtractor.h

+13-12
Original file line numberDiff line numberDiff line change
@@ -31,28 +31,29 @@ namespace langutil
3131

3232
struct LineColumn
3333
{
34-
int line;
35-
int column;
34+
int line = {-1};
35+
int column = {-1};
3636

37+
LineColumn() = default;
3738
LineColumn(std::tuple<int, int> const& _t): line{std::get<0>(_t)}, column{std::get<1>(_t)} {}
38-
LineColumn(int _line, int _column): line{_line}, column{_column} {}
39-
LineColumn(): line{-1}, column{-1} {}
4039
};
4140

4241
struct SourceReference
4342
{
44-
std::string message; ///< A message that relates to this source reference (such as a warning or an error message).
45-
std::string sourceName; ///< Underlying source name (for example the filename).
46-
LineColumn position; ///< Actual (error) position this source reference is surrounding.
47-
bool multiline; ///< Indicates whether the actual SourceReference is truncated to one line.
48-
std::string text; ///< Extracted source code text (potentially truncated if multiline or too long).
49-
int startColumn; ///< Highlighting range-start of text field.
50-
int endColumn; ///< Highlighting range-end of text field.
43+
std::string message; ///< A message that relates to this source reference (such as a warning or an error message).
44+
std::string sourceName; ///< Underlying source name (for example the filename).
45+
LineColumn position; ///< Actual (error) position this source reference is surrounding.
46+
bool multiline = {false}; ///< Indicates whether the actual SourceReference is truncated to one line.
47+
std::string text; ///< Extracted source code text (potentially truncated if multiline or too long).
48+
int startColumn = {-1}; ///< Highlighting range-start of text field.
49+
int endColumn = {-1}; ///< Highlighting range-end of text field.
5150

5251
/// Constructs a SourceReference containing a message only.
5352
static SourceReference MessageOnly(std::string _msg)
5453
{
55-
return SourceReference{std::move(_msg), "", LineColumn{-1, -1}, false, "", -1, -1};
54+
SourceReference sref;
55+
sref.message = std::move(_msg);
56+
return sref;
5657
}
5758
};
5859

liblll/CodeFragment.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class CodeFragment
4141
public:
4242
using ReadCallback = std::function<std::string(std::string const&)>;
4343

44-
CodeFragment() {}
44+
CodeFragment() = default;
4545
CodeFragment(sp::utree const& _t, CompilerState& _s, ReadCallback const& _readFile, bool _allowASM = false);
4646

4747
static CodeFragment compile(std::string const& _src, CompilerState& _s, ReadCallback const& _readFile);

libsolidity/analysis/ControlFlowGraph.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ struct CFGNode
103103
/** Describes the control flow of a function. */
104104
struct FunctionFlow
105105
{
106-
virtual ~FunctionFlow() {}
106+
virtual ~FunctionFlow() = default;
107+
107108
/// Entry node. Control flow of the function starts here.
108109
/// This node is empty and does not have any entries.
109110
CFGNode* entry = nullptr;

libsolidity/ast/ASTAnnotations.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ using TypePointer = std::shared_ptr<Type const>;
4646

4747
struct ASTAnnotation
4848
{
49-
virtual ~ASTAnnotation() {}
49+
virtual ~ASTAnnotation() = default;
5050
};
5151

5252
struct DocTag
@@ -57,7 +57,7 @@ struct DocTag
5757

5858
struct DocumentedAnnotation
5959
{
60-
virtual ~DocumentedAnnotation() {}
60+
virtual ~DocumentedAnnotation() = default;
6161
/// Mapping docstring tag name -> content.
6262
std::multimap<std::string, DocTag> docTags;
6363
};

libsolidity/ast/Types.h

-1
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,6 @@ class FixedBytesType: public Type
601601
class BoolType: public Type
602602
{
603603
public:
604-
BoolType() {}
605604
Category category() const override { return Category::Bool; }
606605
std::string richIdentifier() const override { return "t_bool"; }
607606
TypeResult unaryOperatorResult(Token _operator) const override;

libsolidity/codegen/LValue.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class LValue
4949
m_context(_compilerContext), m_dataType(_dataType) {}
5050

5151
public:
52-
virtual ~LValue() {}
52+
virtual ~LValue() = default;
5353
/// @returns the number of stack slots occupied by the lvalue reference
5454
virtual unsigned sizeOnStack() const { return 1; }
5555
/// Copies the value of the current lvalue to the top of the stack and, if @a _remove is true,

libsolidity/parsing/Parser.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class Parser::ASTNodeFactory
4848
explicit ASTNodeFactory(Parser const& _parser):
4949
m_parser(_parser), m_location{_parser.position(), -1, _parser.source()} {}
5050
ASTNodeFactory(Parser const& _parser, ASTPointer<ASTNode> const& _childNode):
51-
m_parser(_parser), m_location(_childNode->location()) {}
51+
m_parser(_parser), m_location{_childNode->location()} {}
5252

5353
void markEndPosition() { m_location.end = m_parser.endPosition(); }
5454
void setLocation(SourceLocation const& _location) { m_location = _location; }

libsolidity/parsing/Parser.h

+5-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,10 @@ class Parser: public langutil::ParserBase
4747

4848
struct VarDeclParserOptions
4949
{
50+
// This is actually not needed, but due to a defect in the C++ standard, we have to.
51+
// https://stackoverflow.com/questions/17430377
5052
VarDeclParserOptions() {}
53+
5154
bool allowVar = false;
5255
bool isStateVariable = false;
5356
bool allowIndexed = false;
@@ -85,7 +88,7 @@ class Parser: public langutil::ParserBase
8588
ASTPointer<EnumDefinition> parseEnumDefinition();
8689
ASTPointer<EnumValue> parseEnumValue();
8790
ASTPointer<VariableDeclaration> parseVariableDeclaration(
88-
VarDeclParserOptions const& _options = VarDeclParserOptions(),
91+
VarDeclParserOptions const& _options = {},
8992
ASTPointer<TypeName> const& _lookAheadArrayType = ASTPointer<TypeName>()
9093
);
9194
ASTPointer<ModifierDefinition> parseModifierDefinition();
@@ -99,7 +102,7 @@ class Parser: public langutil::ParserBase
99102
ASTPointer<FunctionTypeName> parseFunctionType();
100103
ASTPointer<Mapping> parseMapping();
101104
ASTPointer<ParameterList> parseParameterList(
102-
VarDeclParserOptions const& _options,
105+
VarDeclParserOptions const& _options = {},
103106
bool _allowEmpty = true
104107
);
105108
ASTPointer<Block> parseBlock(ASTPointer<ASTString> const& _docString = {});

libyul/Dialect.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ struct Dialect: boost::noncopyable
5454
virtual BuiltinFunction const* builtin(YulString /*_name*/) const { return nullptr; }
5555

5656
Dialect(AsmFlavour _flavour): flavour(_flavour) {}
57-
virtual ~Dialect() {}
57+
virtual ~Dialect() = default;
5858

5959
static std::shared_ptr<Dialect> yul()
6060
{

libyul/Object.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ struct AsmAnalysisInfo;
3737
*/
3838
struct ObjectNode
3939
{
40-
virtual ~ObjectNode() {}
40+
virtual ~ObjectNode() = default;
4141
virtual std::string toString(bool _yul) const = 0;
4242

4343
YulString name;

libyul/YulString.h

+6-6
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,9 @@ class YulStringRepository: boost::noncopyable
4242
size_t id;
4343
std::uint64_t hash;
4444
};
45-
YulStringRepository():
46-
m_strings{std::make_shared<std::string>()},
47-
m_hashToID{std::make_pair(emptyHash(), 0)}
48-
{}
45+
46+
YulStringRepository() = default;
47+
4948
static YulStringRepository& instance()
5049
{
5150
static YulStringRepository inst;
@@ -80,9 +79,10 @@ class YulStringRepository: boost::noncopyable
8079
return hash;
8180
}
8281
static constexpr std::uint64_t emptyHash() { return 14695981039346656037u; }
82+
8383
private:
84-
std::vector<std::shared_ptr<std::string>> m_strings;
85-
std::unordered_multimap<std::uint64_t, size_t> m_hashToID;
84+
std::vector<std::shared_ptr<std::string>> m_strings = {std::make_shared<std::string>()};
85+
std::unordered_multimap<std::uint64_t, size_t> m_hashToID = {{emptyHash(), 0}};
8686
};
8787

8888
/// Wrapper around handles into the YulString repository.

libyul/backends/evm/AbstractAssembly.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class AbstractAssembly
5555
using LabelID = size_t;
5656
using SubID = size_t;
5757

58-
virtual ~AbstractAssembly() {}
58+
virtual ~AbstractAssembly() = default;
5959

6060
/// Set a new source location valid starting from the next instruction.
6161
virtual void setSourceLocation(langutil::SourceLocation const& _location) = 0;

libyul/backends/evm/EVMAssembly.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class EVMAssembly: public AbstractAssembly
3838
{
3939
public:
4040
explicit EVMAssembly(bool _evm15 = false): m_evm15(_evm15) { }
41-
virtual ~EVMAssembly() {}
41+
virtual ~EVMAssembly() = default;
4242

4343
/// Set a new source location valid starting from the next instruction.
4444
void setSourceLocation(langutil::SourceLocation const& _location) override;

libyul/backends/evm/EVMDialect.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ using namespace dev::solidity;
3838

3939

4040
EVMDialect::EVMDialect(AsmFlavour _flavour, bool _objectAccess):
41-
Dialect(_flavour), m_objectAccess(_objectAccess)
41+
Dialect{_flavour}, m_objectAccess(_objectAccess)
4242
{
4343
// The EVM instructions will be moved to builtins at some point.
4444
if (!m_objectAccess)

libyul/optimiser/RedundantAssignEliminator.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ class RedundantAssignEliminator: public ASTWalker
115115
static void run(Block& _ast);
116116

117117
private:
118-
RedundantAssignEliminator() {}
118+
RedundantAssignEliminator() = default;
119119

120120
class State
121121
{

solc/CommandLineInterface.h

-2
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ enum class DocumentationType: uint8_t;
4141
class CommandLineInterface
4242
{
4343
public:
44-
CommandLineInterface() {}
45-
4644
/// Parse command line arguments and return false if we should not continue
4745
bool parseArguments(int _argc, char** _argv);
4846
/// Parse the files and create source code objects

test/TestCase.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class TestCase
3636
public:
3737
using TestCaseCreator = std::unique_ptr<TestCase>(*)(std::string const&);
3838

39-
virtual ~TestCase() {}
39+
virtual ~TestCase() = default;
4040

4141
/// Runs the test case.
4242
/// Outputs error messages to @arg _stream. Each line of output is prefixed with @arg _linePrefix.

test/libsolidity/GasMeter.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ namespace test
4444
class GasMeterTestFramework: public SolidityExecutionFramework
4545
{
4646
public:
47-
GasMeterTestFramework() { }
4847
void compile(string const& _sourceCode)
4948
{
5049
m_compiler.reset(false);

test/libsolidity/SolidityABIJSON.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ namespace test
3838
class JSONInterfaceChecker
3939
{
4040
public:
41-
JSONInterfaceChecker(): m_compilerStack() {}
42-
4341
void checkInterface(std::string const& _code, std::string const& _contractName, std::string const& _expectedInterfaceString)
4442
{
4543
m_compilerStack.reset(false);

test/libsolidity/SolidityNatspecJSON.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ namespace test
3939
class DocumentationChecker
4040
{
4141
public:
42-
DocumentationChecker(): m_compilerStack() {}
43-
4442
void checkNatspec(
4543
std::string const& _code,
4644
std::string const& _contractName,

test/libsolidity/SolidityOptimizer.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ namespace test
4545
class OptimizerTestFramework: public SolidityExecutionFramework
4646
{
4747
public:
48-
OptimizerTestFramework() { }
49-
5048
bytes const& compileAndRunWithOptimizer(
5149
std::string const& _sourceCode,
5250
u256 const& _value = 0,

0 commit comments

Comments
 (0)