mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Checked arithmetic by default.
This commit is contained in:
@@ -190,6 +190,28 @@ void SyntaxChecker::endVisit(ForStatement const&)
|
||||
m_inLoopDepth--;
|
||||
}
|
||||
|
||||
bool SyntaxChecker::visit(Block const& _block)
|
||||
{
|
||||
if (_block.unchecked())
|
||||
{
|
||||
if (m_uncheckedArithmetic)
|
||||
m_errorReporter.syntaxError(
|
||||
1941_error,
|
||||
_block.location(),
|
||||
"\"unchecked\" blocks cannot be nested."
|
||||
);
|
||||
|
||||
m_uncheckedArithmetic = true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void SyntaxChecker::endVisit(Block const& _block)
|
||||
{
|
||||
if (_block.unchecked())
|
||||
m_uncheckedArithmetic = false;
|
||||
}
|
||||
|
||||
bool SyntaxChecker::visit(Continue const& _continueStatement)
|
||||
{
|
||||
if (m_inLoopDepth <= 0)
|
||||
@@ -288,8 +310,15 @@ bool SyntaxChecker::visit(InlineAssembly const& _inlineAssembly)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool SyntaxChecker::visit(PlaceholderStatement const&)
|
||||
bool SyntaxChecker::visit(PlaceholderStatement const& _placeholder)
|
||||
{
|
||||
if (m_uncheckedArithmetic)
|
||||
m_errorReporter.syntaxError(
|
||||
2573_error,
|
||||
_placeholder.location(),
|
||||
"The placeholder statement \"_\" cannot be used inside an \"unchecked\" block."
|
||||
);
|
||||
|
||||
m_placeholderFound = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -71,6 +71,9 @@ private:
|
||||
bool visit(ForStatement const& _forStatement) override;
|
||||
void endVisit(ForStatement const& _forStatement) override;
|
||||
|
||||
bool visit(Block const& _block) override;
|
||||
void endVisit(Block const& _block) override;
|
||||
|
||||
bool visit(Continue const& _continueStatement) override;
|
||||
bool visit(Break const& _breakStatement) override;
|
||||
|
||||
@@ -100,6 +103,9 @@ private:
|
||||
/// Flag that indicates whether some version pragma was present.
|
||||
bool m_versionPragmaFound = false;
|
||||
|
||||
/// Flag that indicates whether we are inside an unchecked block.
|
||||
bool m_uncheckedArithmetic = false;
|
||||
|
||||
int m_inLoopDepth = 0;
|
||||
std::optional<ContractKind> m_currentContractKind;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user