Commit 5a186104 authored by Milo Yip's avatar Milo Yip

Fixes warnings

parent 5852c42b
......@@ -64,7 +64,7 @@ solution "test"
defines { "_CRT_SECURE_NO_WARNINGS" }
configuration "gmake"
buildoptions "-msse4.2 -Werror=cast-qual"
buildoptions "-msse4.2 -Werror -Wall -Wextra"
project "gtest"
kind "StaticLib"
......@@ -86,6 +86,8 @@ solution "test"
project "unittest"
kind "ConsoleApp"
buildoptions "-Weffc++"
files {
"../include/**.h",
"../test/unittest/**.cpp",
......@@ -149,8 +151,8 @@ solution "example"
configuration "vs*"
defines { "_CRT_SECURE_NO_WARNINGS" }
-- configuration "gmake"
-- buildoptions "-Weverything"
configuration "gmake"
buildoptions "-Werror -Wall -Wextra -Weffc++"
project "condense"
kind "ConsoleApp"
......
......@@ -58,9 +58,17 @@ private:
class Dependent : public Person {
public:
Dependent(const std::string& name, unsigned age, Education* education = 0) : Person(name, age), education_(education) {}
Dependent(const Dependent& rhs) : Person(rhs) { education_ = (rhs.education_ == 0) ? 0 : new Education(*rhs.education_); }
Dependent(const Dependent& rhs) : Person(rhs), education_(0) { education_ = (rhs.education_ == 0) ? 0 : new Education(*rhs.education_); }
virtual ~Dependent();
Dependent& operator=(const Dependent& rhs) {
if (this == &rhs)
return *this;
delete education_;
education_ = (rhs.education_ == 0) ? 0 : new Education(*rhs.education_);
return *this;
}
template <typename Writer>
void Serialize(Writer& writer) const {
writer.StartObject();
......@@ -77,6 +85,7 @@ public:
}
private:
Education *education_;
};
......@@ -86,7 +95,7 @@ Dependent::~Dependent() {
class Employee : public Person {
public:
Employee(const std::string& name, unsigned age, bool married) : Person(name, age), married_(married) {}
Employee(const std::string& name, unsigned age, bool married) : Person(name, age), dependents_(), married_(married) {}
virtual ~Employee();
void AddDependent(const Dependent& dependent) {
......
......@@ -10,6 +10,11 @@
#pragma warning(disable : 4127) // conditional expression is constant
#endif
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Weffc++"
#endif
namespace rapidjson {
// Forward declaration.
......@@ -59,7 +64,7 @@ public:
//@{
//! Default constructor creates a null value.
GenericValue() : flags_(kNullFlag) {}
GenericValue() : data_(), flags_(kNullFlag) {}
//! Copy constructor is not permitted.
private:
......@@ -72,7 +77,7 @@ public:
\param type Type of the value.
\note Default content for number is zero.
*/
GenericValue(Type type) : data_() {
GenericValue(Type type) : data_(), flags_() {
static const unsigned defaultFlags[7] = {
kNullFlag, kFalseFlag, kTrueFlag, kObjectFlag, kArrayFlag, kConstStringFlag,
kNumberAnyFlag
......@@ -92,24 +97,24 @@ public:
GenericValue(const GenericValue<Encoding,SourceAllocator>& rhs, Allocator & allocator);
//! Constructor for boolean value.
explicit GenericValue(bool b) : flags_(b ? kTrueFlag : kFalseFlag) {}
explicit GenericValue(bool b) : data_(), flags_(b ? kTrueFlag : kFalseFlag) {}
//! Constructor for int value.
explicit GenericValue(int i) : flags_(kNumberIntFlag) {
explicit GenericValue(int i) : data_(), flags_(kNumberIntFlag) {
data_.n.i64 = i;
if (i >= 0)
flags_ |= kUintFlag | kUint64Flag;
}
//! Constructor for unsigned value.
explicit GenericValue(unsigned u) : flags_(kNumberUintFlag) {
explicit GenericValue(unsigned u) : data_(), flags_(kNumberUintFlag) {
data_.n.u64 = u;
if (!(u & 0x80000000))
flags_ |= kIntFlag | kInt64Flag;
}
//! Constructor for int64_t value.
explicit GenericValue(int64_t i64) : flags_(kNumberInt64Flag) {
explicit GenericValue(int64_t i64) : data_(), flags_(kNumberInt64Flag) {
data_.n.i64 = i64;
if (i64 >= 0) {
flags_ |= kNumberUint64Flag;
......@@ -123,7 +128,7 @@ public:
}
//! Constructor for uint64_t value.
explicit GenericValue(uint64_t u64) : flags_(kNumberUint64Flag) {
explicit GenericValue(uint64_t u64) : data_(), flags_(kNumberUint64Flag) {
data_.n.u64 = u64;
if (!(u64 & UINT64_C(0x8000000000000000)))
flags_ |= kInt64Flag;
......@@ -134,10 +139,10 @@ public:
}
//! Constructor for double value.
explicit GenericValue(double d) : flags_(kNumberDoubleFlag) { data_.n.d = d; }
explicit GenericValue(double d) : data_(), flags_(kNumberDoubleFlag) { data_.n.d = d; }
//! Constructor for constant string (i.e. do not make a copy of string)
GenericValue(const Ch* s, SizeType length) {
GenericValue(const Ch* s, SizeType length) : data_(), flags_() {
RAPIDJSON_ASSERT(s != NULL);
flags_ = kConstStringFlag;
data_.s.str = s;
......@@ -145,13 +150,13 @@ public:
}
//! Constructor for constant string (i.e. do not make a copy of string)
explicit GenericValue(const Ch* s) { SetStringRaw(s, internal::StrLen(s)); }
explicit GenericValue(const Ch* s) : data_(), flags_() { SetStringRaw(s, internal::StrLen(s)); }
//! Constructor for copy-string (i.e. do make a copy of string)
GenericValue(const Ch* s, SizeType length, Allocator& allocator) { SetStringRaw(s, length, allocator); }
GenericValue(const Ch* s, SizeType length, Allocator& allocator) : data_(), flags_() { SetStringRaw(s, length, allocator); }
//! Constructor for copy-string (i.e. do make a copy of string)
GenericValue(const Ch*s, Allocator& allocator) { SetStringRaw(s, internal::StrLen(s), allocator); }
GenericValue(const Ch*s, Allocator& allocator) : data_(), flags_() { SetStringRaw(s, internal::StrLen(s), allocator); }
//! Destructor.
/*! Need to destruct elements of array, members of object, or copy-string.
......@@ -962,4 +967,8 @@ GenericValue<Encoding,Allocator>::GenericValue(const GenericValue<Encoding,Sourc
#pragma warning(pop)
#endif
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
#endif // RAPIDJSON_DOCUMENT_H_
......@@ -3,6 +3,11 @@
#include "rapidjson.h"
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Weffc++"
#endif
namespace rapidjson {
//! Input byte stream wrapper with a statically bound encoding.
......@@ -31,7 +36,7 @@ public:
size_t PutEnd(Ch*) { RAPIDJSON_ASSERT(false); return 0; }
private:
// Prohibit assignment for VC C4512 warning
EncodedInputStream(const EncodedInputStream&);
EncodedInputStream& operator=(const EncodedInputStream&);
InputByteStream& is_;
......@@ -65,7 +70,7 @@ public:
size_t PutEnd(Ch*) { RAPIDJSON_ASSERT(false); return 0; }
private:
// Prohibit assignment for VC C4512 warning
EncodedOutputStream(const EncodedOutputStream&);
EncodedOutputStream& operator=(const EncodedOutputStream&);
OutputByteStream& os_;
......@@ -110,6 +115,9 @@ public:
size_t PutEnd(Ch*) { RAPIDJSON_ASSERT(false); return 0; }
private:
AutoUTFInputStream(const AutoUTFInputStream&);
AutoUTFInputStream& operator=(const AutoUTFInputStream&);
// Detect encoding type with BOM or RFC 4627
void DetectType() {
// BOM (Byte Order Mark):
......@@ -230,6 +238,9 @@ public:
size_t PutEnd(Ch*) { RAPIDJSON_ASSERT(false); return 0; }
private:
AutoUTFOutputStream(const AutoUTFOutputStream&);
AutoUTFOutputStream& operator=(const AutoUTFOutputStream&);
void PutBOM() {
typedef void (*PutBOMFunc)(OutputByteStream&);
static const PutBOMFunc f[] = { RAPIDJSON_ENCODINGS_FUNC(PutBOM) };
......@@ -247,4 +258,8 @@ private:
} // namespace rapidjson
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
#endif // RAPIDJSON_FILESTREAM_H_
......@@ -3,6 +3,11 @@
#include "rapidjson.h"
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Weffc++"
#endif
namespace rapidjson {
///////////////////////////////////////////////////////////////////////////////
......@@ -524,4 +529,8 @@ struct Transcoder<Encoding, Encoding> {
} // namespace rapidjson
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
#endif // RAPIDJSON_ENCODINGS_H_
......@@ -69,11 +69,6 @@ private:
bool eof_;
};
template<>
struct StreamTraits<FileReadStream> {
typedef FileReadStream StreamCopyType; // Enable stream copy optimization.
};
} // namespace rapidjson
#endif // RAPIDJSON_FILESTREAM_H_
......@@ -28,6 +28,10 @@ public:
size_t PutEnd(char*) { return 0; }
private:
// Prohibit copy constructor & assignment operator.
FileStream(const FileStream&);
FileStream& operator=(const FileStream&);
void Read() {
RAPIDJSON_ASSERT(fp_ != 0);
int c = fgetc(fp_);
......
......@@ -56,6 +56,10 @@ public:
size_t PutEnd(char*) { RAPIDJSON_ASSERT(false); return 0; }
private:
// Prohibit copy constructor & assignment operator.
FileWriteStream(const FileWriteStream&);
FileWriteStream& operator=(const FileWriteStream&);
FILE* fp_;
char *buffer_;
char *bufferEnd_;
......
......@@ -69,6 +69,10 @@ public:
size_t GetCapacity() const { return stack_capacity_; }
private:
// Prohibit copy constructor & assignment operator.
Stack(const Stack&);
Stack& operator=(const Stack&);
Allocator* allocator_;
Allocator* own_allocator_;
char *stack_;
......
......@@ -3,6 +3,11 @@
#include "writer.h"
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Weffc++"
#endif
namespace rapidjson {
//! Writer with indentation and spacing.
......@@ -162,8 +167,17 @@ protected:
Ch indentChar_;
unsigned indentCharCount_;
private:
// Prohibit copy constructor & assignment operator.
PrettyWriter(const PrettyWriter&);
PrettyWriter& operator=(const PrettyWriter&);
};
} // namespace rapidjson
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
#endif // RAPIDJSON_RAPIDJSON_H_
......@@ -284,8 +284,9 @@ protected:
static const int kDefaultDoublePrecision = 6;
private:
// Prohibit assignment for VC C4512 warning
Writer& operator=(const Writer& w);
// Prohibit copy constructor & assignment operator.
Writer(const Writer&);
Writer& operator=(const Writer&);
};
} // namespace rapidjson
......
......@@ -24,8 +24,22 @@
#ifdef __cplusplus
// gtest indirectly included inttypes.h, without __STDC_CONSTANT_MACROS.
#ifndef __STDC_CONSTANT_MACROS
# define __STDC_CONSTANT_MACROS 1 // required by C++ standard
#endif
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Weffc++"
#endif
#include "gtest/gtest.h"
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
#ifdef _MSC_VER
#define _CRTDBG_MAP_ALLOC
#include <crtdbg.h>
......@@ -35,6 +49,8 @@
//! Base class for all performance tests
class PerfTest : public ::testing::Test {
public:
PerfTest() : filename_(), json_(), length_(), whitespace_(), whitespace_length_() {}
virtual void SetUp() {
FILE *fp = fopen(filename_ = "data/sample.json", "rb");
if (!fp)
......@@ -68,8 +84,14 @@ public:
virtual void TearDown() {
free(json_);
free(whitespace_);
json_ = 0;
whitespace_ = 0;
}
private:
PerfTest(const PerfTest&);
PerfTest& operator=(const PerfTest&);
protected:
const char* filename_;
char *json_;
......
......@@ -21,6 +21,8 @@ using namespace rapidjson;
class RapidJson : public PerfTest {
public:
RapidJson() : temp_(), doc_() {}
virtual void SetUp() {
PerfTest::SetUp();
......@@ -36,6 +38,10 @@ public:
free(temp_);
}
private:
RapidJson(const RapidJson&);
RapidJson& operator=(const RapidJson&);
protected:
char *temp_;
Document doc_;
......@@ -165,6 +171,11 @@ TEST_F(RapidJson, DocumentTraverse) {
}
}
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Weffc++"
#endif
struct ValueCounter : public BaseReaderHandler<> {
ValueCounter() : count_(1) {} // root
......@@ -174,6 +185,10 @@ struct ValueCounter : public BaseReaderHandler<> {
SizeType count_;
};
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
TEST_F(RapidJson, DocumentAccept) {
for (size_t i = 0; i < kTrialCount; i++) {
ValueCounter counter;
......
......@@ -8,14 +8,21 @@ using namespace rapidjson;
class EncodedStreamTest : public ::testing::Test {
public:
EncodedStreamTest() : json_(), length_() {}
virtual void SetUp() {
json_ = ReadFile("utf8.json", true, &length_);
}
virtual void TearDown() {
free(json_);
json_ = 0;
}
private:
EncodedStreamTest(const EncodedStreamTest&);
EncodedStreamTest& operator=(const EncodedStreamTest&);
protected:
static FILE* Open(const char* filename) {
char buffer[1024];
......@@ -131,7 +138,6 @@ protected:
remove(filename);
}
const char* filename_;
char *json_;
size_t length_;
};
......
......@@ -7,6 +7,9 @@
using namespace rapidjson;
class FileStreamTest : public ::testing::Test {
public:
FileStreamTest() : filename_(), json_(), length_() {}
virtual void SetUp() {
FILE *fp = fopen(filename_ = "data/sample.json", "rb");
if (!fp)
......@@ -24,8 +27,13 @@ class FileStreamTest : public ::testing::Test {
virtual void TearDown() {
free(json_);
json_ = 0;
}
private:
FileStreamTest(const FileStreamTest&);
FileStreamTest& operator=(const FileStreamTest&);
protected:
const char* filename_;
char *json_;
......
......@@ -5,6 +5,11 @@
using namespace rapidjson;
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Weffc++"
#endif
template<bool expect>
struct ParseBoolHandler : BaseReaderHandler<> {
ParseBoolHandler() : step_(0) {}
......@@ -33,7 +38,7 @@ TEST(Reader, ParseFalse) {
}
struct ParseIntHandler : BaseReaderHandler<> {
ParseIntHandler() : step_(0) {}
ParseIntHandler() : step_(0), actual_() {}
void Default() { FAIL(); }
void Int(int i) { actual_ = i; step_++; }
......@@ -42,7 +47,7 @@ struct ParseIntHandler : BaseReaderHandler<> {
};
struct ParseUintHandler : BaseReaderHandler<> {
ParseUintHandler() : step_(0) {}
ParseUintHandler() : step_(0), actual_() {}
void Default() { FAIL(); }
void Uint(unsigned i) { actual_ = i; step_++; }
......@@ -51,7 +56,7 @@ struct ParseUintHandler : BaseReaderHandler<> {
};
struct ParseInt64Handler : BaseReaderHandler<> {
ParseInt64Handler() : step_(0) {}
ParseInt64Handler() : step_(0), actual_() {}
void Default() { FAIL(); }
void Int64(int64_t i) { actual_ = i; step_++; }
......@@ -60,7 +65,7 @@ struct ParseInt64Handler : BaseReaderHandler<> {
};
struct ParseUint64Handler : BaseReaderHandler<> {
ParseUint64Handler() : step_(0) {}
ParseUint64Handler() : step_(0), actual_() {}
void Default() { FAIL(); }
void Uint64(uint64_t i) { actual_ = i; step_++; }
......@@ -69,7 +74,7 @@ struct ParseUint64Handler : BaseReaderHandler<> {
};
struct ParseDoubleHandler : BaseReaderHandler<> {
ParseDoubleHandler() : step_(0) {}
ParseDoubleHandler() : step_(0), actual_() {}
void Default() { FAIL(); }
void Double(double d) { actual_ = d; step_++; }
......@@ -183,8 +188,12 @@ TEST(Reader, ParseNumber_Error) {
template <typename Encoding>
struct ParseStringHandler : BaseReaderHandler<Encoding> {
ParseStringHandler() : str_(0), length_(0) {}
ParseStringHandler() : str_(0), length_(0), copy_() {}
~ParseStringHandler() { EXPECT_TRUE(str_ != 0); if (copy_) free(const_cast<typename Encoding::Ch*>(str_)); }
ParseStringHandler(const ParseStringHandler&);
ParseStringHandler& operator=(const ParseStringHandler&);
void Default() { FAIL(); }
void String(const typename Encoding::Ch* str, size_t length, bool copy) {
EXPECT_EQ(0, str_);
......@@ -651,3 +660,7 @@ TEST(Reader, CustomStringStream) {
reader.ParseObject<0>(s, h);
EXPECT_EQ(20u, h.step_);
}
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
#ifndef UNITTEST_H_
#define UNITTEST_H_
// gtest indirectly included inttypes.h, without __STDC_CONSTANT_MACROS.
#ifndef __STDC_CONSTANT_MACROS
# define __STDC_CONSTANT_MACROS 1 // required by C++ standard
#endif
#ifdef _MSC_VER
#define _CRTDBG_MAP_ALLOC
#include <crtdbg.h>
#pragma warning(disable : 4996) // 'function': was declared deprecated
#endif
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Weffc++"
#endif
#include "gtest/gtest.h"
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
template <typename Ch>
inline size_t StrLen(const Ch* s) {
const Ch* p = s;
......
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