Fix warnings in clang for C++11

This commit is contained in:
Milo Yip
2016-01-23 14:37:15 +08:00
parent 534da223f7
commit a6eb15d274
12 changed files with 121 additions and 11 deletions

View File

@@ -16,6 +16,11 @@
#include "rapidjson/document.h"
#include <algorithm>
#ifdef __clang__
RAPIDJSON_DIAG_PUSH
RAPIDJSON_DIAG_OFF(c++98-compat)
#endif
using namespace rapidjson;
TEST(Value, DefaultConstructor) {
@@ -764,15 +769,15 @@ TEST(Value, Array) {
#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
// PushBack(GenericValue&&, Allocator&);
{
Value y(kArrayType);
y.PushBack(Value(true), allocator);
y.PushBack(std::move(Value(kArrayType).PushBack(Value(1), allocator).PushBack("foo", allocator)), allocator);
EXPECT_EQ(2u, y.Size());
EXPECT_TRUE(y[0].IsTrue());
EXPECT_TRUE(y[1].IsArray());
EXPECT_EQ(2u, y[1].Size());
EXPECT_TRUE(y[1][0].IsInt());
EXPECT_TRUE(y[1][1].IsString());
Value y2(kArrayType);
y2.PushBack(Value(true), allocator);
y2.PushBack(std::move(Value(kArrayType).PushBack(Value(1), allocator).PushBack("foo", allocator)), allocator);
EXPECT_EQ(2u, y2.Size());
EXPECT_TRUE(y2[0].IsTrue());
EXPECT_TRUE(y2[1].IsArray());
EXPECT_EQ(2u, y2[1].Size());
EXPECT_TRUE(y2[1][0].IsInt());
EXPECT_TRUE(y2[1][1].IsString());
}
#endif
@@ -1354,3 +1359,27 @@ TEST(Value, AcceptTerminationByHandler) {
TEST_TERMINATION(11, "{\"a\":[]}");
TEST_TERMINATION(12, "{\"a\":[]}");
}
struct ValueIntComparer {
bool operator()(const Value& lhs, const Value& rhs) const {
return lhs.GetInt() < rhs.GetInt();
}
};
#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
TEST(Value, Sorting) {
Value::AllocatorType allocator;
Value a(kArrayType);
a.PushBack(5, allocator);
a.PushBack(1, allocator);
a.PushBack(3, allocator);
std::sort(a.Begin(), a.End(), ValueIntComparer());
EXPECT_EQ(1, a[0].GetInt());
EXPECT_EQ(3, a[1].GetInt());
EXPECT_EQ(5, a[2].GetInt());
}
#endif
#ifdef __clang__
RAPIDJSON_DIAG_POP
#endif