Skip to content

Commit

Permalink
Add more compiler flags
Browse files Browse the repository at this point in the history
  • Loading branch information
kuznetsss committed Sep 13, 2023
1 parent f090961 commit 192f0db
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 43 deletions.
26 changes: 25 additions & 1 deletion CMake/Settings.cmake
Original file line number Diff line number Diff line change
@@ -1,10 +1,34 @@
target_compile_options (clio PUBLIC
set(COMPILER_FLAGS
-Wall
-Wcast-align
-Wdouble-promotion
-Wextra
-Werror
-Wformat=2
-Wimplicit-fallthrough
-Wmisleading-indentation
-Wno-narrowing
-Wno-deprecated-declarations
-Wno-dangling-else
-Wno-unused-but-set-variable
-Wnon-virtual-dtor
-Wnull-dereference
-Wold-style-cast
-Woverloaded-virtual
-pedantic
-Wpedantic
-Wunused
)
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
list(APPEND COMPILER_FLAGS
-Wduplicated-branches
-Wduplicated-cond
-Wlifetime
-Wlogical-op
-Wuseless-cast
)
endif ()

# See https://github.com/cpp-best-practices/cppbestpractices/blob/master/02-Use_the_Tools_Available.md#gcc--clang for the flags description

target_compile_options (clio PUBLIC ${COMPILER_FLAGS})
4 changes: 2 additions & 2 deletions src/data/LedgerCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,15 @@ LedgerCache::getObjectHitRate() const
{
if (!objectReqCounter_)
return 1;
return ((float)objectHitCounter_) / objectReqCounter_;
return static_cast<float>(objectHitCounter_) / objectReqCounter_;
}

float
LedgerCache::getSuccessorHitRate() const
{
if (!successorReqCounter_)
return 1;
return ((float)successorHitCounter_) / successorReqCounter_;
return static_cast<float>(successorHitCounter_) / successorReqCounter_;
}

} // namespace data
4 changes: 2 additions & 2 deletions src/etl/LoadBalancer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ LoadBalancer::forwardToRippled(
std::string const& clientIp,
boost::asio::yield_context yield) const
{
srand((unsigned)time(0));
srand(static_cast<unsigned>(time(0)));
auto sourceIdx = rand() % sources_.size();
auto numAttempts = 0u;

Expand Down Expand Up @@ -193,7 +193,7 @@ template <class Func>
bool
LoadBalancer::execute(Func f, uint32_t ledgerSequence)
{
srand((unsigned)time(0));
srand(static_cast<unsigned>(time(0)));
auto sourceIdx = rand() % sources_.size();
auto numAttempts = 0;

Expand Down
2 changes: 1 addition & 1 deletion src/etl/impl/AsyncData.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class AsyncCallData
auto& obj = *(cur_->mutable_ledger_objects()->mutable_objects(i));
if (!more && nextPrefix_ != 0x00)
{
if (((unsigned char)obj.key()[0]) >= nextPrefix_)
if (static_cast<unsigned char>(obj.key()[0]) >= nextPrefix_)
continue;
}
cacheUpdates.push_back(
Expand Down
2 changes: 1 addition & 1 deletion src/etl/impl/LedgerLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class LedgerLoader
result.nfTokensData.push_back(*maybeNFT);

result.accountTxData.emplace_back(txMeta, sttx.getTransactionID());
std::string keyStr{(const char*)sttx.getTransactionID().data(), 32};
std::string keyStr{reinterpret_cast<const char*>(sttx.getTransactionID().data()), 32};
backend_->writeTransaction(
std::move(keyStr),
ledger.seq,
Expand Down
1 change: 1 addition & 0 deletions src/rpc/BookChangesHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ class BookChanges final
case ripple::ttOFFER_CREATE:
if (tx->isFieldPresent(ripple::sfOfferSequence))
return tx->getFieldU32(ripple::sfOfferSequence);
[[fallthrough]];
default:
return std::nullopt;
}
Expand Down
2 changes: 1 addition & 1 deletion unittests/SubscriptionManagerTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ TEST_F(SubscriptionManagerSimpleBackendTest, SubscriptionManagerAccountProposedT
})";
subManagerPtr->forwardProposedTransaction(json::parse(dummyTransaction).get_object());
CheckSubscriberMessage(dummyTransaction, session);
auto rawIdle = (MockSession*)(sessionIdle.get());
auto rawIdle = static_cast<MockSession*>(sessionIdle.get());
EXPECT_EQ("", rawIdle->message);
}

Expand Down
13 changes: 6 additions & 7 deletions unittests/SubscriptionTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#include <boost/json/parse.hpp>
#include <gmock/gmock.h>

namespace json = boost::json;
using namespace feed;

// io_context
Expand Down Expand Up @@ -83,9 +82,9 @@ TEST_F(SubscriptionTest, SubscriptionPublish)
sub.publish(std::make_shared<std::string>("message"));
ctx.restart();
ctx.run();
MockSession* p1 = (MockSession*)(session1.get());
MockSession* p1 = static_cast<MockSession*>(session1.get());
EXPECT_EQ(p1->message, "message");
MockSession* p2 = (MockSession*)(session2.get());
MockSession* p2 = static_cast<MockSession*>(session2.get());
EXPECT_EQ(p2->message, "message");
sub.unsubscribe(session1);
ctx.restart();
Expand Down Expand Up @@ -166,9 +165,9 @@ TEST_F(SubscriptionMapTest, SubscriptionMapPublish)
subMap.publish(std::make_shared<std::string>(topic2Message.data()), topic2); // rvalue
ctx.restart();
ctx.run();
MockSession* p1 = (MockSession*)(session1.get());
MockSession* p1 = static_cast<MockSession*>(session1.get());
EXPECT_EQ(p1->message, topic1Message);
MockSession* p2 = (MockSession*)(session2.get());
MockSession* p2 = static_cast<MockSession*>(session2.get());
EXPECT_EQ(p2->message, topic2Message);
}

Expand All @@ -190,9 +189,9 @@ TEST_F(SubscriptionMapTest, SubscriptionMapDeadRemoveSubscriber)
subMap.publish(std::make_shared<std::string>(topic2Message), topic2); // rvalue
ctx.restart();
ctx.run();
MockDeadSession* p1 = (MockDeadSession*)(session1.get());
MockDeadSession* p1 = static_cast<MockDeadSession*>(session1.get());
EXPECT_EQ(p1->dead(), true);
MockSession* p2 = (MockSession*)(session2.get());
MockSession* p2 = static_cast<MockSession*>(session2.get());
EXPECT_EQ(p2->message, topic2Message);
subMap.publish(message1, topic1);
ctx.restart();
Expand Down
54 changes: 27 additions & 27 deletions unittests/data/cassandra/BackendTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -400,8 +400,8 @@ TEST_F(BackendCassandraTest, Basic)
EXPECT_EQ(ledgerInfoToBlob(*retLgr), ledgerInfoToBlob(lgrInfoNext));
auto txns = backend->fetchAllTransactionsInLedger(lgrInfoNext.seq, yield);
ASSERT_EQ(txns.size(), 1);
EXPECT_STREQ((const char*)txns[0].transaction.data(), (const char*)txnBlob.data());
EXPECT_STREQ((const char*)txns[0].metadata.data(), (const char*)metaBlob.data());
EXPECT_STREQ(reinterpret_cast<const char*>(txns[0].transaction.data()), static_cast<const char*>(txnBlob.data()));
EXPECT_STREQ(reinterpret_cast<const char*>(txns[0].metadata.data()), static_cast<const char*>(metaBlob.data()));
auto hashes = backend->fetchAllTransactionHashesInLedger(lgrInfoNext.seq, yield);
EXPECT_EQ(hashes.size(), 1);
EXPECT_EQ(ripple::strHex(hashes[0]), hashHex);
Expand All @@ -423,10 +423,10 @@ TEST_F(BackendCassandraTest, Basic)
EXPECT_TRUE(key256.parseHex(accountIndexHex));
auto obj = backend->fetchLedgerObject(key256, lgrInfoNext.seq, yield);
EXPECT_TRUE(obj);
EXPECT_STREQ((const char*)obj->data(), (const char*)accountBlob.data());
EXPECT_STREQ(reinterpret_cast<const char*>(obj->data()), static_cast<const char*>(accountBlob.data()));
obj = backend->fetchLedgerObject(key256, lgrInfoNext.seq + 1, yield);
EXPECT_TRUE(obj);
EXPECT_STREQ((const char*)obj->data(), (const char*)accountBlob.data());
EXPECT_STREQ(reinterpret_cast<const char*>(obj->data()), static_cast<const char*>(accountBlob.data()));
obj = backend->fetchLedgerObject(key256, lgrInfoOld.seq - 1, yield);
EXPECT_FALSE(obj);
}
Expand Down Expand Up @@ -462,13 +462,13 @@ TEST_F(BackendCassandraTest, Basic)
EXPECT_TRUE(key256.parseHex(accountIndexHex));
auto obj = backend->fetchLedgerObject(key256, lgrInfoNext.seq, yield);
EXPECT_TRUE(obj);
EXPECT_STREQ((const char*)obj->data(), (const char*)accountBlob.data());
EXPECT_STREQ(reinterpret_cast<const char*>(obj->data()), static_cast<const char*>(accountBlob.data()));
obj = backend->fetchLedgerObject(key256, lgrInfoNext.seq + 1, yield);
EXPECT_TRUE(obj);
EXPECT_STREQ((const char*)obj->data(), (const char*)accountBlob.data());
EXPECT_STREQ(reinterpret_cast<const char*>(obj->data()), static_cast<const char*>(accountBlob.data()));
obj = backend->fetchLedgerObject(key256, lgrInfoNext.seq - 1, yield);
EXPECT_TRUE(obj);
EXPECT_STREQ((const char*)obj->data(), (const char*)accountBlobOld.data());
EXPECT_STREQ(reinterpret_cast<const char*>(obj->data()), static_cast<const char*>(accountBlobOld.data()));
obj = backend->fetchLedgerObject(key256, lgrInfoOld.seq - 1, yield);
EXPECT_FALSE(obj);
}
Expand Down Expand Up @@ -504,7 +504,7 @@ TEST_F(BackendCassandraTest, Basic)
EXPECT_FALSE(obj);
obj = backend->fetchLedgerObject(key256, lgrInfoNext.seq - 2, yield);
EXPECT_TRUE(obj);
EXPECT_STREQ((const char*)obj->data(), (const char*)accountBlobOld.data());
EXPECT_STREQ(reinterpret_cast<const char*>(obj->data()), static_cast<const char*>(accountBlobOld.data()));
obj = backend->fetchLedgerObject(key256, lgrInfoOld.seq - 1, yield);
EXPECT_FALSE(obj);
}
Expand All @@ -517,7 +517,7 @@ TEST_F(BackendCassandraTest, Basic)
for (auto& blob : res)
{
++key;
std::string keyStr{(const char*)key.data(), key.size()};
std::string keyStr{reinterpret_cast<const char*>(key.data()), key.size()};
blob.first = keyStr;
blob.second = std::to_string(ledgerSequence) + keyStr;
}
Expand All @@ -537,7 +537,7 @@ TEST_F(BackendCassandraTest, Basic)
for (auto& blob : res)
{
++base;
std::string hashStr{(const char*)base.data(), base.size()};
std::string hashStr{reinterpret_cast<const char*>(base.data()), base.size()};
std::string txnStr = "tx" + std::to_string(ledgerSequence) + hashStr;
std::string metaStr = "meta" + std::to_string(ledgerSequence) + hashStr;
blob = std::make_tuple(hashStr, txnStr, metaStr);
Expand Down Expand Up @@ -641,8 +641,8 @@ TEST_F(BackendCassandraTest, Basic)
bool found = false;
for (auto [retTxn, retMeta, retSeq, retDate] : retTxns)
{
if (std::strncmp((const char*)retTxn.data(), (const char*)txn.data(), txn.size()) == 0 &&
std::strncmp((const char*)retMeta.data(), (const char*)meta.data(), meta.size()) == 0)
if (std::strncmp(reinterpret_cast<const char*>(retTxn.data()), static_cast<const char*>(txn.data()), txn.size()) == 0 &&
std::strncmp(reinterpret_cast<const char*>(retMeta.data()), static_cast<const char*>(meta.data()), meta.size()) == 0)
found = true;
}
ASSERT_TRUE(found);
Expand All @@ -665,8 +665,8 @@ TEST_F(BackendCassandraTest, Basic)
{
auto [txn, meta, seq, date] = retData[i];
auto [hash, expTxn, expMeta] = data[i];
EXPECT_STREQ((const char*)txn.data(), (const char*)expTxn.data());
EXPECT_STREQ((const char*)meta.data(), (const char*)expMeta.data());
EXPECT_STREQ(reinterpret_cast<const char*>(txn.data()), static_cast<const char*>(expTxn.data()));
EXPECT_STREQ(reinterpret_cast<const char*>(meta.data()), static_cast<const char*>(expMeta.data()));
}
}
std::vector<ripple::uint256> keys;
Expand All @@ -676,7 +676,7 @@ TEST_F(BackendCassandraTest, Basic)
if (obj.size())
{
ASSERT_TRUE(retObj.has_value());
EXPECT_STREQ((const char*)obj.data(), (const char*)retObj->data());
EXPECT_STREQ(static_cast<const char*>(obj.data()), reinterpret_cast<const char*>(retObj->data()));
}
else
{
Expand All @@ -696,7 +696,7 @@ TEST_F(BackendCassandraTest, Basic)
if (obj.size())
{
ASSERT_TRUE(retObj.size());
EXPECT_STREQ((const char*)obj.data(), (const char*)retObj.data());
EXPECT_STREQ(static_cast<const char*>(obj.data()), reinterpret_cast<const char*>(retObj.data()));
}
else
{
Expand Down Expand Up @@ -746,7 +746,7 @@ TEST_F(BackendCassandraTest, Basic)
for (auto account : rec.accounts)
{
allAccountTx[lgrInfoNext.seq][account].push_back(
std::string{(const char*)rec.txHash.data(), rec.txHash.size()});
std::string{reinterpret_cast<const char*>(rec.txHash.data()), rec.txHash.size()});
}
}
EXPECT_EQ(objs.size(), 25);
Expand Down Expand Up @@ -779,7 +779,7 @@ TEST_F(BackendCassandraTest, Basic)
for (auto account : rec.accounts)
{
allAccountTx[lgrInfoNext.seq][account].push_back(
std::string{(const char*)rec.txHash.data(), rec.txHash.size()});
std::string{reinterpret_cast<const char*>(rec.txHash.data()), rec.txHash.size()});
}
}
EXPECT_EQ(objs.size(), 25);
Expand Down Expand Up @@ -978,10 +978,10 @@ TEST_F(BackendCassandraTest, CacheIntegration)
EXPECT_TRUE(key256.parseHex(accountIndexHex));
auto obj = backend->fetchLedgerObject(key256, lgrInfoNext.seq, yield);
EXPECT_TRUE(obj);
EXPECT_STREQ((const char*)obj->data(), (const char*)accountBlob.data());
EXPECT_STREQ(reinterpret_cast<const char*>(obj->data()), static_cast<const char*>(accountBlob.data()));
obj = backend->fetchLedgerObject(key256, lgrInfoNext.seq + 1, yield);
EXPECT_TRUE(obj);
EXPECT_STREQ((const char*)obj->data(), (const char*)accountBlob.data());
EXPECT_STREQ(reinterpret_cast<const char*>(obj->data()), static_cast<const char*>(accountBlob.data()));
obj = backend->fetchLedgerObject(key256, lgrInfoOld.seq - 1, yield);
EXPECT_FALSE(obj);
}
Expand Down Expand Up @@ -1016,13 +1016,13 @@ TEST_F(BackendCassandraTest, CacheIntegration)
EXPECT_TRUE(key256.parseHex(accountIndexHex));
auto obj = backend->fetchLedgerObject(key256, lgrInfoNext.seq, yield);
EXPECT_TRUE(obj);
EXPECT_STREQ((const char*)obj->data(), (const char*)accountBlob.data());
EXPECT_STREQ(reinterpret_cast<const char*>(obj->data()), static_cast<const char*>(accountBlob.data()));
obj = backend->fetchLedgerObject(key256, lgrInfoNext.seq + 1, yield);
EXPECT_TRUE(obj);
EXPECT_STREQ((const char*)obj->data(), (const char*)accountBlob.data());
EXPECT_STREQ(reinterpret_cast<const char*>(obj->data()), static_cast<const char*>(accountBlob.data()));
obj = backend->fetchLedgerObject(key256, lgrInfoNext.seq - 1, yield);
EXPECT_TRUE(obj);
EXPECT_STREQ((const char*)obj->data(), (const char*)accountBlobOld.data());
EXPECT_STREQ(reinterpret_cast<const char*>(obj->data()), static_cast<const char*>(accountBlobOld.data()));
obj = backend->fetchLedgerObject(key256, lgrInfoOld.seq - 1, yield);
EXPECT_FALSE(obj);
}
Expand Down Expand Up @@ -1058,7 +1058,7 @@ TEST_F(BackendCassandraTest, CacheIntegration)
EXPECT_FALSE(obj);
obj = backend->fetchLedgerObject(key256, lgrInfoNext.seq - 2, yield);
EXPECT_TRUE(obj);
EXPECT_STREQ((const char*)obj->data(), (const char*)accountBlobOld.data());
EXPECT_STREQ(reinterpret_cast<const char*>(obj->data()), static_cast<const char*>(accountBlobOld.data()));
obj = backend->fetchLedgerObject(key256, lgrInfoOld.seq - 1, yield);
EXPECT_FALSE(obj);
}
Expand All @@ -1071,7 +1071,7 @@ TEST_F(BackendCassandraTest, CacheIntegration)
for (auto& blob : res)
{
++key;
std::string keyStr{(const char*)key.data(), key.size()};
std::string keyStr{reinterpret_cast<const char*>(key.data()), key.size()};
blob.first = keyStr;
blob.second = std::to_string(ledgerSequence) + keyStr;
}
Expand Down Expand Up @@ -1153,7 +1153,7 @@ TEST_F(BackendCassandraTest, CacheIntegration)
if (obj.size())
{
ASSERT_TRUE(retObj.has_value());
EXPECT_STREQ((const char*)obj.data(), (const char*)retObj->data());
EXPECT_STREQ(static_cast<const char*>(obj.data()), reinterpret_cast<const char*>(retObj->data()));
}
else
{
Expand All @@ -1173,7 +1173,7 @@ TEST_F(BackendCassandraTest, CacheIntegration)
if (obj.size())
{
ASSERT_TRUE(retObj.size());
EXPECT_STREQ((const char*)obj.data(), (const char*)retObj.data());
EXPECT_STREQ(static_cast<const char*>(obj.data()), reinterpret_cast<const char*>(retObj.data()));
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion unittests/util/StringUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ ripple::uint256
binaryStringToUint256(std::string const& bin)
{
ripple::uint256 uint;
return uint.fromVoid((void const*)bin.data());
return uint.fromVoid(static_cast<void const*>(bin.data()));
}

std::string
Expand Down

0 comments on commit 192f0db

Please sign in to comment.