Skip to content

Commit 58e4cc6

Browse files
benldrmnMarenz
authored andcommitted
Increase use of C++ constexpr constant expressions in code base as described in issue #7720
1 parent 13691df commit 58e4cc6

File tree

6 files changed

+8
-8
lines changed

6 files changed

+8
-8
lines changed

CODING_STYLE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ tuple<float, float> myNamespace::meanAndSigma(vector<float> const& _v)
8181
- Copyright
8282
- License (e.g. see COPYING)
8383
2. Never use `#ifdef`/`#define`/`#endif` file guards. Prefer `#pragma` once as first line below file comment.
84-
3. Prefer static const variable to value macros.
84+
3. Prefer static constexpr variables to value macros.
8585
4. Prefer inline constexpr functions to function macros.
8686
5. Split complex macro on multiple lines with `\`.
8787

libsolidity/analysis/DocStringTagParser.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include <boost/algorithm/string.hpp>
3535

3636
#include <regex>
37+
#include <string_view>
3738

3839
using namespace std;
3940
using namespace solidity;
@@ -233,7 +234,7 @@ void DocStringTagParser::parseDocStrings(
233234

234235
for (auto const& [tagName, tagValue]: _annotation.docTags)
235236
{
236-
string static const customPrefix("custom:");
237+
string_view static constexpr customPrefix("custom:");
237238
if (tagName == "custom" || tagName == "custom:")
238239
m_errorReporter.docstringParsingError(
239240
6564_error,

libyul/Utilities.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ string solidity::yul::reindent(string const& _code)
4242
{
4343
int constexpr indentationWidth = 4;
4444

45-
auto const static countBraces = [](string const& _s) noexcept -> int
45+
auto constexpr static countBraces = [](string const& _s) noexcept -> int
4646
{
4747
auto const i = _s.find("//");
4848
auto const e = i == _s.npos ? end(_s) : next(begin(_s), static_cast<ptrdiff_t>(i));

test/EVMHost.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -856,7 +856,7 @@ void EVMHostPrinter::selfdestructRecords()
856856

857857
void EVMHostPrinter::callRecords()
858858
{
859-
static const auto callKind = [](evmc_call_kind _kind) -> string
859+
static auto constexpr callKind = [](evmc_call_kind _kind) -> string
860860
{
861861
switch (_kind)
862862
{

test/ExecutionFramework.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,8 @@ namespace solidity::test
4949
using rational = boost::rational<bigint>;
5050

5151
// The ether and gwei denominations; here for ease of use where needed within code.
52-
static const u256 gwei = u256(1) << 9;
53-
static const u256 ether = u256(1) << 18;
54-
52+
static u256 const gwei = u256(1) << 9;
53+
static u256 const ether = u256(1) << 18;
5554
class ExecutionFramework
5655
{
5756

test/tools/fuzzer_common.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ void FuzzerUtil::testCompilerJsonInterface(string const& _input, bool _optimize,
7878
void FuzzerUtil::forceSMT(StringMap& _input)
7979
{
8080
// Add SMT checker pragma if not already present in source
81-
static const char* smtPragma = "pragma experimental SMTChecker;";
81+
static auto constexpr smtPragma = "pragma experimental SMTChecker;";
8282
for (auto &sourceUnit: _input)
8383
if (sourceUnit.second.find(smtPragma) == string::npos)
8484
sourceUnit.second += smtPragma;

0 commit comments

Comments
 (0)