Commit 36eaa6a6 authored by Kenton Varda's avatar Kenton Varda

Enable some useful Clang warnings, fix some bugs it detected. Especially,…

Enable some useful Clang warnings, fix some bugs it detected.  Especially, eliminate all dynamic initializers.
parent 1bdce291
......@@ -4,8 +4,10 @@ EKAM=`which ekam || echo .ekam/bin/ekam`
ifeq ($(CXX),clang++)
# Clang's verbose diagnostics don't play nice with the Ekam Eclipse plugin's error parsing,
# so disable them.
EXTRA_FLAG=-fno-caret-diagnostics
# so disable them. Also enable some useful Clang warnings (dunno if GCC supports them, and don't
# care).
EXTRA_FLAG=-fno-caret-diagnostics -Wglobal-constructors -Wextra-semi
# EXTRA_FLAG=-fno-caret-diagnostics -Weverything -Wno-c++98-compat -Wno-shadow -Wno-c++98-compat-pedantic -Wno-padded -Wno-weak-vtables -Wno-gnu -Wno-unused-parameter -Wno-sign-conversion -Wno-undef -Wno-shorten-64-to-32 -Wno-conversion -Wno-unreachable-code -Wno-non-virtual-dtor
else
EXTRA_FLAG=
endif
......
......@@ -138,9 +138,6 @@ struct RawSchema {
struct MemberInfo {
uint16_t unionIndex; // 0 = not in a union, >0 = parent union's index + 1
uint16_t index; // index of the member
MemberInfo() = default;
inline MemberInfo(uint16_t unionIndex, uint16_t index): unionIndex(unionIndex), index(index) {}
};
const MemberInfo* membersByName;
......
......@@ -129,7 +129,8 @@ public:
loader.allocate<_::RawSchema::MemberInfo>(*count);
uint pos = 0;
for (auto& member: members) {
result[pos++] = _::RawSchema::MemberInfo(member.first.first, member.second);
result[pos++] = {kj::implicitCast<uint16_t>(member.first.first),
kj::implicitCast<uint16_t>(member.second)};
}
KJ_DASSERT(pos == *count);
return result;
......
......@@ -34,7 +34,7 @@ class SnappyInputStream::InputStreamSnappySource: public snappy::Source {
public:
inline InputStreamSnappySource(BufferedInputStream& inputStream)
: inputStream(inputStream) {}
inline ~InputStreamSnappySource() noexcept {};
inline ~InputStreamSnappySource() noexcept {}
// implements snappy::Source ---------------------------------------
......
......@@ -24,9 +24,6 @@
#include "array.h"
namespace kj {
ArrayDisposer::~ArrayDisposer() noexcept(false) {}
namespace _ { // private
struct HeapArrayDisposer::ExceptionGuard {
......
......@@ -37,7 +37,8 @@ class ArrayDisposer {
// Much like Disposer from memory.h.
protected:
virtual ~ArrayDisposer() noexcept(false);
// Do not declare a destructor, as doing so will force a global initializer for
// HeapArrayDisposer::instance.
virtual void disposeImpl(void* firstElement, size_t elementSize, size_t elementCount,
size_t capacity, void (*destroyElement)(void*)) const = 0;
......
......@@ -100,11 +100,11 @@ typedef unsigned char byte;
// Don't force inline in debug mode.
#endif
#define KJ_NORETURN __attribute__((noreturn));
#define KJ_UNUSED __attribute__((unused));
#define KJ_NORETURN __attribute__((noreturn))
#define KJ_UNUSED __attribute__((unused))
#if __clang__
#define KJ_UNUSED_MEMBER __attribute__((unused));
#define KJ_UNUSED_MEMBER __attribute__((unused))
// Inhibits "unused" warning for member variables. Only Clang produces such a warning, while GCC
// complains if the attribute is set on members.
#else
......
......@@ -245,7 +245,7 @@ class FdInputStream: public InputStream {
// An InputStream wrapping a file descriptor.
public:
explicit FdInputStream(int fd): fd(fd) {};
explicit FdInputStream(int fd): fd(fd) {}
explicit FdInputStream(AutoCloseFd fd): fd(fd), autoclose(mv(fd)) {}
KJ_DISALLOW_COPY(FdInputStream);
~FdInputStream() noexcept(false);
......@@ -261,7 +261,7 @@ class FdOutputStream: public OutputStream {
// An OutputStream wrapping a file descriptor.
public:
explicit FdOutputStream(int fd): fd(fd) {};
explicit FdOutputStream(int fd): fd(fd) {}
explicit FdOutputStream(AutoCloseFd fd): fd(fd), autoclose(mv(fd)) {}
KJ_DISALLOW_COPY(FdOutputStream);
~FdOutputStream() noexcept(false);
......
......@@ -25,6 +25,4 @@
namespace kj {
Disposer::~Disposer() noexcept(false) {}
} // namespace kj
......@@ -40,7 +40,8 @@ class Disposer {
// custom memory allocators.
protected:
virtual ~Disposer() noexcept(false);
// Do not declare a destructor, as doing so will force a global initializer for each HeapDisposer
// instance. Eww!
virtual void disposeImpl(void* pointer) const = 0;
// Disposes of the object, given a pointer to the beginning of the object. If the object is
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment