mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Increase use of C++ constexpr constant expressions in code base as described in issue #7720
This commit is contained in:
parent
13691dfbaa
commit
58e4cc62e0
@ -81,7 +81,7 @@ tuple<float, float> myNamespace::meanAndSigma(vector<float> const& _v)
|
|||||||
- Copyright
|
- Copyright
|
||||||
- License (e.g. see COPYING)
|
- License (e.g. see COPYING)
|
||||||
2. Never use `#ifdef`/`#define`/`#endif` file guards. Prefer `#pragma` once as first line below file comment.
|
2. Never use `#ifdef`/`#define`/`#endif` file guards. Prefer `#pragma` once as first line below file comment.
|
||||||
3. Prefer static const variable to value macros.
|
3. Prefer static constexpr variables to value macros.
|
||||||
4. Prefer inline constexpr functions to function macros.
|
4. Prefer inline constexpr functions to function macros.
|
||||||
5. Split complex macro on multiple lines with `\`.
|
5. Split complex macro on multiple lines with `\`.
|
||||||
|
|
||||||
|
@ -34,6 +34,7 @@
|
|||||||
#include <boost/algorithm/string.hpp>
|
#include <boost/algorithm/string.hpp>
|
||||||
|
|
||||||
#include <regex>
|
#include <regex>
|
||||||
|
#include <string_view>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace solidity;
|
using namespace solidity;
|
||||||
@ -233,7 +234,7 @@ void DocStringTagParser::parseDocStrings(
|
|||||||
|
|
||||||
for (auto const& [tagName, tagValue]: _annotation.docTags)
|
for (auto const& [tagName, tagValue]: _annotation.docTags)
|
||||||
{
|
{
|
||||||
string static const customPrefix("custom:");
|
string_view static constexpr customPrefix("custom:");
|
||||||
if (tagName == "custom" || tagName == "custom:")
|
if (tagName == "custom" || tagName == "custom:")
|
||||||
m_errorReporter.docstringParsingError(
|
m_errorReporter.docstringParsingError(
|
||||||
6564_error,
|
6564_error,
|
||||||
|
@ -42,7 +42,7 @@ string solidity::yul::reindent(string const& _code)
|
|||||||
{
|
{
|
||||||
int constexpr indentationWidth = 4;
|
int constexpr indentationWidth = 4;
|
||||||
|
|
||||||
auto const static countBraces = [](string const& _s) noexcept -> int
|
auto constexpr static countBraces = [](string const& _s) noexcept -> int
|
||||||
{
|
{
|
||||||
auto const i = _s.find("//");
|
auto const i = _s.find("//");
|
||||||
auto const e = i == _s.npos ? end(_s) : next(begin(_s), static_cast<ptrdiff_t>(i));
|
auto const e = i == _s.npos ? end(_s) : next(begin(_s), static_cast<ptrdiff_t>(i));
|
||||||
|
@ -856,7 +856,7 @@ void EVMHostPrinter::selfdestructRecords()
|
|||||||
|
|
||||||
void EVMHostPrinter::callRecords()
|
void EVMHostPrinter::callRecords()
|
||||||
{
|
{
|
||||||
static const auto callKind = [](evmc_call_kind _kind) -> string
|
static auto constexpr callKind = [](evmc_call_kind _kind) -> string
|
||||||
{
|
{
|
||||||
switch (_kind)
|
switch (_kind)
|
||||||
{
|
{
|
||||||
|
@ -49,9 +49,8 @@ namespace solidity::test
|
|||||||
using rational = boost::rational<bigint>;
|
using rational = boost::rational<bigint>;
|
||||||
|
|
||||||
// The ether and gwei denominations; here for ease of use where needed within code.
|
// The ether and gwei denominations; here for ease of use where needed within code.
|
||||||
static const u256 gwei = u256(1) << 9;
|
static u256 const gwei = u256(1) << 9;
|
||||||
static const u256 ether = u256(1) << 18;
|
static u256 const ether = u256(1) << 18;
|
||||||
|
|
||||||
class ExecutionFramework
|
class ExecutionFramework
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -78,7 +78,7 @@ void FuzzerUtil::testCompilerJsonInterface(string const& _input, bool _optimize,
|
|||||||
void FuzzerUtil::forceSMT(StringMap& _input)
|
void FuzzerUtil::forceSMT(StringMap& _input)
|
||||||
{
|
{
|
||||||
// Add SMT checker pragma if not already present in source
|
// Add SMT checker pragma if not already present in source
|
||||||
static const char* smtPragma = "pragma experimental SMTChecker;";
|
static auto constexpr smtPragma = "pragma experimental SMTChecker;";
|
||||||
for (auto &sourceUnit: _input)
|
for (auto &sourceUnit: _input)
|
||||||
if (sourceUnit.second.find(smtPragma) == string::npos)
|
if (sourceUnit.second.find(smtPragma) == string::npos)
|
||||||
sourceUnit.second += smtPragma;
|
sourceUnit.second += smtPragma;
|
||||||
|
Loading…
Reference in New Issue
Block a user