Fix clang warnings

This commit is contained in:
Howard Hinnant
2014-02-25 15:49:27 -05:00
committed by Vinnie Falco
parent 9bf1a76e91
commit cd30e552a7
28 changed files with 115 additions and 66 deletions

View File

@@ -300,8 +300,16 @@ template <typename Type>
inline Type Atomic<Type>::operator+= (const Type amountToAdd) noexcept
{
#if BEAST_ATOMICS_MAC
# ifdef __clang__
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wint-to-void-pointer-cast"
# pragma clang diagnostic ignored "-Wint-to-pointer-cast"
# endif
return sizeof (Type) == 4 ? (Type) OSAtomicAdd32Barrier ((int32_t) castTo32Bit (amountToAdd), (BEAST_MAC_ATOMICS_VOLATILE int32_t*) &value)
: (Type) OSAtomicAdd64Barrier ((int64_t) amountToAdd, (BEAST_MAC_ATOMICS_VOLATILE int64_t*) &value);
# ifdef __clang__
# pragma clang diagnostic pop
# endif
#elif BEAST_ATOMICS_WINDOWS
return sizeof (Type) == 4 ? (Type) (beast_InterlockedExchangeAdd ((volatile long*) &value, (long) amountToAdd) + (long) amountToAdd)
: (Type) (beast_InterlockedExchangeAdd64 ((volatile __int64*) &value, (__int64) amountToAdd) + (__int64) amountToAdd);
@@ -320,8 +328,16 @@ template <typename Type>
inline Type Atomic<Type>::operator++() noexcept
{
#if BEAST_ATOMICS_MAC
# ifdef __clang__
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wint-to-void-pointer-cast"
# pragma clang diagnostic ignored "-Wint-to-pointer-cast"
# endif
return sizeof (Type) == 4 ? (Type) OSAtomicIncrement32Barrier ((BEAST_MAC_ATOMICS_VOLATILE int32_t*) &value)
: (Type) OSAtomicIncrement64Barrier ((BEAST_MAC_ATOMICS_VOLATILE int64_t*) &value);
# ifdef __clang__
# pragma clang diagnostic pop
# endif
#elif BEAST_ATOMICS_WINDOWS
return sizeof (Type) == 4 ? (Type) beast_InterlockedIncrement ((volatile long*) &value)
: (Type) beast_InterlockedIncrement64 ((volatile __int64*) &value);
@@ -334,8 +350,16 @@ template <typename Type>
inline Type Atomic<Type>::operator--() noexcept
{
#if BEAST_ATOMICS_MAC
# ifdef __clang__
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wint-to-void-pointer-cast"
# pragma clang diagnostic ignored "-Wint-to-pointer-cast"
# endif
return sizeof (Type) == 4 ? (Type) OSAtomicDecrement32Barrier ((BEAST_MAC_ATOMICS_VOLATILE int32_t*) &value)
: (Type) OSAtomicDecrement64Barrier ((BEAST_MAC_ATOMICS_VOLATILE int64_t*) &value);
# ifdef __clang__
# pragma clang diagnostic pop
# endif
#elif BEAST_ATOMICS_WINDOWS
return sizeof (Type) == 4 ? (Type) beast_InterlockedDecrement ((volatile long*) &value)
: (Type) beast_InterlockedDecrement64 ((volatile __int64*) &value);

View File

@@ -1469,7 +1469,7 @@ operator[] (Key const& key)
std::piecewise_construct, std::forward_as_tuple (key),
std::forward_as_tuple ()));
chronological.list.push_back (*p);
auto const iter (m_cont.insert_commit (*p, d));
m_cont.insert_commit (*p, d);
return p->value.second;
}
return result.first->value.second;
@@ -1492,7 +1492,7 @@ operator[] (Key&& key)
std::forward_as_tuple (std::move (key)),
std::forward_as_tuple ()));
chronological.list.push_back (*p);
auto const iter (m_cont.insert_commit (*p, d));
m_cont.insert_commit (*p, d);
return p->value.second;
}
return result.first->value.second;

View File

@@ -2077,7 +2077,7 @@ operator[] (Key const& key)
std::forward_as_tuple (key),
std::forward_as_tuple ()));
chronological.list.push_back (*p);
auto const iter (m_cont.insert_commit (*p, d));
m_cont.insert_commit (*p, d);
return p->value.second;
}
return result.first->value.second;
@@ -2103,7 +2103,7 @@ operator[] (Key&& key)
std::forward_as_tuple (std::move (key)),
std::forward_as_tuple ()));
chronological.list.push_back (*p);
auto const iter (m_cont.insert_commit (*p, d));
m_cont.insert_commit (*p, d);
return p->value.second;
}
return result.first->value.second;

View File

@@ -335,7 +335,7 @@ public:
void log (std::vector <boost::asio::const_buffer> const& buffers)
{
buffers;
(void)buffers;
#if BEAST_STATSDCOLLECTOR_TRACING_ENABLED
std::stringstream ss;
for (auto const& buffer : buffers)

View File

@@ -343,9 +343,9 @@ public:
const beast_wchar c = src.getAndAdvance();
const size_t bytesNeeded = DestCharPointerType::getBytesRequiredFor (c);
maxBytes -= bytesNeeded;
if (c == 0 || maxBytes < 0)
if (c == 0 || maxBytes < bytesNeeded)
break;
maxBytes -= bytesNeeded;
dest.write (c);
}

View File

@@ -64,6 +64,9 @@ public:
#pragma warning (push)
#pragma warning (disable: 4127) // conditional expression is constant
#pragma warning (disable: 4146) // unary minus operator applied to unsigned type, result still unsigned
#elif defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wtautological-compare"
#endif
// pass in a pointer to the END of a buffer..
template <typename IntegerType>
@@ -86,6 +89,8 @@ public:
}
#ifdef _MSC_VER
#pragma warning (pop)
#elif defined(__clang__)
#pragma clang diagnostic pop
#endif
struct StackArrayStream : public std::basic_streambuf <char, std::char_traits <char> >

View File

@@ -33,9 +33,8 @@ protected:
SharedHandler. A reference to the SharedHandler is maintained
for the lifetime of the composed operation.
*/
ComposedAsyncOperation (std::size_t size, SharedHandlerPtr const& ptr)
: m_size (size)
, m_ptr (ptr)
explicit ComposedAsyncOperation (SharedHandlerPtr const& ptr)
: m_ptr (ptr)
{
// Illegal to do anything with handler here, because
// usually it hasn't been assigned by the derived class yet.
@@ -93,7 +92,6 @@ protected:
}
private:
std::size_t const m_size;
SharedHandlerPtr const m_ptr;
};

View File

@@ -129,7 +129,7 @@ private:
AsyncOp (HandshakeDetectLogicType <Logic>& logic, Stream& stream,
BuffersType& buffer, SharedHandlerPtr const& handler)
: ComposedAsyncOperation (sizeof (*this), handler)
: ComposedAsyncOperation (handler)
, m_logic (logic)
, m_stream (stream)
, m_buffer (buffer)

View File

@@ -27,7 +27,7 @@ class TestPeerDetails
public:
virtual ~TestPeerDetails () { }
virtual String name () = 0;
virtual String name () const = 0;
virtual Socket& get_socket () = 0;

View File

@@ -54,7 +54,7 @@ public:
return ".tcp?";
}
String name ()
String name () const
{
return getArgName (m_protocol);
}

View File

@@ -29,9 +29,8 @@ namespace PeerFinder {
class Counts
{
public:
explicit Counts (clock_type& clock)
: m_clock (clock)
, m_attempts (0)
Counts ()
: m_attempts (0)
, m_active (0)
, m_in_max (0)
, m_in_active (0)
@@ -299,8 +298,6 @@ private:
}
private:
clock_type& m_clock;
/** Outbound connection attempts. */
int m_attempts;

View File

@@ -65,7 +65,7 @@ public:
clock_type& clock,
Journal journal)
: stopping (false)
, counts (clock)
, counts ()
, livecache (clock, Journal (
journal, Reporting::livecache))
, bootcache (*store, clock, Journal (

View File

@@ -201,8 +201,6 @@ public:
{
SharedState::Access state (m_state);
Table::iterator iter (
state->table.find (*prior.key));
std::pair <Table::iterator, bool> result (
state->table.emplace (key, 0));
entry = &result.first->second;

View File

@@ -87,7 +87,7 @@ public:
Consumer c (logic.newInboundEndpoint (addr));
// Create load until we get a warning
for (std::size_t n (maxLoopCount); n>=0; --n)
for (std::size_t n (maxLoopCount); true; --n)
{
if (n == 0)
{
@@ -104,7 +104,7 @@ public:
}
// Create load until we get dropped
for (std::size_t n (maxLoopCount); n>=0; --n)
for (std::size_t n (maxLoopCount); true; --n)
{
if (n == 0)
{
@@ -127,7 +127,7 @@ public:
expect (c.disconnect ());
}
for (std::size_t n (maxLoopCount); n>=0; --n)
for (std::size_t n (maxLoopCount); true; --n)
{
Consumer c (logic.newInboundEndpoint (addr));
if (n == 0)

View File

@@ -296,6 +296,15 @@ Status BlockBasedTableBuilder::status() const {
return rep_->status;
}
//
// Warning: This function is also being used in the file
// block_based_table_reader.cc even though it is declared static, due
// to the source-file-concatenation build scheme. There is an idential
// file-local function in block_based_table_reader.cc too, but it was
// not being used.
// Do not change this function without reviewing its impact on the code
// in block_based_table_reader.cc.
//
static void DeleteCachedBlock(const Slice& key, void* value) {
Block* block = reinterpret_cast<Block*>(value);
delete block;

View File

@@ -166,10 +166,28 @@ void DeleteBlock(void* arg, void* ignored) {
delete reinterpret_cast<Block*>(arg);
}
void DeleteCachedBlock(const Slice& key, void* value) {
Block* block = reinterpret_cast<Block*>(value);
delete block;
}
//
// Commented out DeleteCachedBlock to silence the following warning:
//
// warning: unused function 'DeleteCachedBlock'
//
// Although it looks like this function is being used later in this file,
// it is not. Instead a file-static function of the same name is being
// used from block_based_table_builder.cc. That function is being found
// because this file and block_based_table_builder.cc are being
// concatenated in ripple_rocksdb.cpp. Fortunately the version of
// DeleteCachedBlock in block_based_table_builder.cc is identical to this
// one. So everything is working.
//
// This function has not been removed because it will need to be
// uncommented in the event we abandon the source file concatenation build
// model. In that event, failure to uncomment this function will lead to a
// compile-time error, not a run-time error (so this is safe).
//
// void DeleteCachedBlock(const Slice& key, void* value) {
// Block* block = reinterpret_cast<Block*>(value);
// delete block;
// }
void DeleteCachedFilter(const Slice& key, void* value) {
auto filter = reinterpret_cast<FilterBlockReader*>(value);

View File

@@ -195,14 +195,19 @@ Data::pointer Interpreter::getUint160Data ()
bool Interpreter::jumpTo (int offset)
{
mInstructionPointer += offset;
if ( (mInstructionPointer < 0) || (mInstructionPointer > mCode->size ()) )
if (offset < 0)
{
mInstructionPointer -= offset;
return (false);
if (-offset > mInstructionPointer)
return false;
}
else
{
if (offset > mCode->size () ||
mInstructionPointer > mCode->size () - offset)
return false;
}
mInstructionPointer += offset;
return (true);
}

View File

@@ -891,7 +891,7 @@ public:
// PropertyStream
//
void onWrite (PropertyStream& stream)
void onWrite (PropertyStream::Map& stream)
{
}

View File

@@ -235,6 +235,13 @@ void SerializedTransaction::setSourceAccount (const RippleAddress& naSource)
setFieldAccount (sfAccount, naSource);
}
Json::Value SerializedTransaction::getJson (int) const
{
Json::Value ret = STObject::getJson (0);
ret["hash"] = getTransactionID ().GetHex ();
return ret;
}
Json::Value SerializedTransaction::getJson (int options, bool binary) const
{
if (binary)
@@ -245,10 +252,7 @@ Json::Value SerializedTransaction::getJson (int options, bool binary) const
ret["hash"] = getTransactionID ().GetHex ();
return ret;
}
Json::Value ret = STObject::getJson (0);
ret["hash"] = getTransactionID ().GetHex ();
return ret;
return getJson(options);
}
std::string SerializedTransaction::getSQLValueHeader ()

View File

@@ -101,7 +101,8 @@ public:
uint256 getTransactionID () const;
virtual Json::Value getJson (int options, bool binary = false) const;
virtual Json::Value getJson (int options) const;
virtual Json::Value getJson (int options, bool binary) const;
void sign (const RippleAddress & naAccountPrivate);
bool checkSign (const RippleAddress & naAccountPublic) const;

View File

@@ -48,11 +48,9 @@ static int s_nodeStoreDBCount = NUMBER (s_nodeStoreDBInit);
class SqliteBackend : public NodeStore::Backend
{
public:
SqliteBackend (size_t keyBytes, std::string const& path, NodeStore::Scheduler& scheduler)
: m_keyBytes (keyBytes)
, m_name (path)
explicit SqliteBackend (std::string const& path)
: m_name (path)
, m_db (new DatabaseCon(path, s_nodeStoreDBInit, s_nodeStoreDBCount))
, m_scheduler (scheduler)
{
String s;
@@ -218,10 +216,8 @@ public:
}
private:
size_t const m_keyBytes;
std::string const m_name;
std::unique_ptr <DatabaseCon> m_db;
NodeStore::Scheduler& m_scheduler;
};
//------------------------------------------------------------------------------
@@ -235,11 +231,10 @@ public:
}
std::unique_ptr <NodeStore::Backend> createInstance (
size_t keyBytes, NodeStore::Parameters const& keyValues,
NodeStore::Scheduler& scheduler, Journal)
size_t, NodeStore::Parameters const& keyValues,
NodeStore::Scheduler&, Journal)
{
return std::make_unique <SqliteBackend> (
keyBytes, keyValues ["path"].toStdString (), scheduler);
return std::make_unique <SqliteBackend> (keyValues ["path"].toStdString ());
}
};

View File

@@ -437,11 +437,11 @@ public:
{
int iDomains = 0;
int iNodes = 0;
Database* db = getApp().getWalletDB ()->getDB ();
#if 0
{
DeprecatedScopedLock sl (getApp().getWalletDB ()->getDBLock ());
Database* db = getApp().getWalletDB ()->getDB ();
if (db->executeSQL (str (boost::format ("SELECT COUNT(*) AS Count FROM SeedDomains WHERE Source='%s' OR Source='%c';") % vsManual % vsValidator)) && db->startIterRows ())
iDomains = db->getInt ("Count");

View File

@@ -44,9 +44,7 @@ public:
private:
// VFALCO DEPRECATED, Use a memory barrier instead of forcing a cache line
int m_pad1; // make sure m_elapsedTime fits in its own cache line
int volatile m_elapsedTime;
int m_pad2;
time_t m_startTime;

View File

@@ -23,8 +23,7 @@ namespace NodeStore {
class NullBackend : public Backend
{
public:
explicit NullBackend (Scheduler& scheduler)
: m_scheduler (scheduler)
NullBackend ()
{
}
@@ -60,7 +59,6 @@ public:
}
private:
Scheduler& m_scheduler;
};
//------------------------------------------------------------------------------
@@ -74,9 +72,9 @@ public:
}
std::unique_ptr <Backend> createInstance (
size_t, Parameters const&, Scheduler& scheduler, Journal journal)
size_t, Parameters const&, Scheduler&, Journal)
{
return std::make_unique <NullBackend> (scheduler);
return std::make_unique <NullBackend> ();
}
};

View File

@@ -100,7 +100,7 @@ public:
return holder.context->get ();
}
String name ()
String name () const
{
return getArgName (m_flags);
}

View File

@@ -161,7 +161,7 @@ protected:
//--------------------------------------------------------------------------
// What would we return from here?
bool native_handle (char const*, void*) const
bool native_handle (char const*, void*)
{
pure_virtual_called (__FILE__, __LINE__);
return false;
@@ -832,7 +832,7 @@ protected:
AsyncOp (MultiSocketType <StreamSocket>& owner, Stream& stream,
handshake_type type, ConstBuffers const& buffers,
SharedHandlerPtr const& handler)
: ComposedAsyncOperation (sizeof (*this), handler)
: ComposedAsyncOperation (handler)
, m_handler (handler)
, m_owner (owner)
, m_stream (stream)

View File

@@ -497,7 +497,7 @@ public:
//
//--------------------------------------------------------------------------
void onWrite (PropertyStream& stream)
void onWrite (PropertyStream::Map& stream)
{
}
@@ -589,7 +589,7 @@ public:
PeerByShortId::iterator const iter (
m_shortIdMap.find (id));
if (iter != m_shortIdMap.end ())
iter->second;
return iter->second;
return Peer::pointer();
}
};

View File

@@ -41,9 +41,8 @@ public:
void add (std::string const& method, handler_type&& handler)
{
std::pair <Map::iterator, bool> result (m_map.emplace (
std::piecewise_construct, std::forward_as_tuple (method),
std::forward_as_tuple (std::move (handler))));
m_map.emplace (std::piecewise_construct, std::forward_as_tuple (method),
std::forward_as_tuple (std::move (handler)));
}
bool dispatch (Request& req)