Skip to content

clang-tidy fixes again #1155

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions include/json/assertions.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,19 @@

// @todo <= add detail about condition in exception
#define JSON_ASSERT(condition) \
{ \
do { \
if (!(condition)) { \
Json::throwLogicError("assert json failed"); \
} \
}
} while (0)

#define JSON_FAIL_MESSAGE(message) \
{ \
do { \
OStringStream oss; \
oss << message; \
Json::throwLogicError(oss.str()); \
abort(); \
}
} while (0)

#else // JSON_USE_EXCEPTION

Expand All @@ -52,8 +52,10 @@
#endif

#define JSON_ASSERT_MESSAGE(condition, message) \
if (!(condition)) { \
JSON_FAIL_MESSAGE(message); \
}
do { \
if (!(condition)) { \
JSON_FAIL_MESSAGE(message); \
} \
} while (0)

#endif // JSON_ASSERTIONS_H_INCLUDED
14 changes: 0 additions & 14 deletions include/json/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,20 +74,6 @@ extern JSON_API int msvc_pre1900_c99_snprintf(char* outBuf, size_t size,
// C++11 should be used directly in JSONCPP.
#define JSONCPP_OVERRIDE override

#if __cplusplus >= 201103L
#define JSONCPP_NOEXCEPT noexcept
#define JSONCPP_OP_EXPLICIT explicit
#elif defined(_MSC_VER) && _MSC_VER < 1900
#define JSONCPP_NOEXCEPT throw()
#define JSONCPP_OP_EXPLICIT explicit
#elif defined(_MSC_VER) && _MSC_VER >= 1900
#define JSONCPP_NOEXCEPT noexcept
#define JSONCPP_OP_EXPLICIT explicit
#else
#define JSONCPP_NOEXCEPT throw()
#define JSONCPP_OP_EXPLICIT
#endif

#ifdef __clang__
#if __has_extension(attribute_deprecated_with_message)
#define JSONCPP_DEPRECATED(message) __attribute__((deprecated(message)))
Expand Down
6 changes: 3 additions & 3 deletions include/json/value.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ namespace Json {
class JSON_API Exception : public std::exception {
public:
Exception(String msg);
~Exception() JSONCPP_NOEXCEPT override;
char const* what() const JSONCPP_NOEXCEPT override;
~Exception() noexcept override;
char const* what() const noexcept override;

protected:
String msg_;
Expand Down Expand Up @@ -421,7 +421,7 @@ class JSON_API Value {
bool empty() const;

/// Return !isNull()
JSONCPP_OP_EXPLICIT operator bool() const;
explicit operator bool() const;

/// Remove all object members and array elements.
/// \pre type() is arrayValue, objectValue, or nullValue
Expand Down
2 changes: 1 addition & 1 deletion src/jsontestrunner/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ static void printValueTree(FILE* fout, Json::Value& value,
Json::Value::Members members(value.getMemberNames());
std::sort(members.begin(), members.end());
Json::String suffix = *(path.end() - 1) == '.' ? "" : ".";
for (auto name : members) {
for (const auto& name : members) {
printValueTree(fout, value[name], path + suffix + name);
}
} break;
Expand Down
4 changes: 2 additions & 2 deletions src/lib_json/json_value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,8 @@ namespace Json {

#if JSON_USE_EXCEPTION
Exception::Exception(String msg) : msg_(std::move(msg)) {}
Exception::~Exception() JSONCPP_NOEXCEPT = default;
char const* Exception::what() const JSONCPP_NOEXCEPT { return msg_.c_str(); }
Exception::~Exception() noexcept = default;
char const* Exception::what() const noexcept { return msg_.c_str(); }
RuntimeError::RuntimeError(String const& msg) : Exception(msg) {}
LogicError::LogicError(String const& msg) : Exception(msg) {}
JSONCPP_NORETURN void throwRuntimeError(String const& msg) {
Expand Down
8 changes: 4 additions & 4 deletions src/test_lib_json/jsontest.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,15 +207,15 @@ TestResult& checkStringEqual(TestResult& result, const Json::String& expected,
/// The predicate may do other assertions and be a member function of the
/// fixture.
#define JSONTEST_ASSERT_PRED(expr) \
{ \
do { \
JsonTest::PredicateContext _minitest_Context = { \
result_->predicateId_, __FILE__, __LINE__, #expr, NULL, NULL}; \
result_->predicateStackTail_->next_ = &_minitest_Context; \
result_->predicateId_ += 1; \
result_->predicateStackTail_ = &_minitest_Context; \
(expr); \
result_->popPredicateContext(); \
}
} while (0)

/// \brief Asserts that two values are equals.
#define JSONTEST_ASSERT_EQUAL(expected, actual) \
Expand All @@ -230,7 +230,7 @@ TestResult& checkStringEqual(TestResult& result, const Json::String& expected,

/// \brief Asserts that a given expression throws an exception
#define JSONTEST_ASSERT_THROWS(expr) \
{ \
do { \
bool _threw = false; \
try { \
expr; \
Expand All @@ -240,7 +240,7 @@ TestResult& checkStringEqual(TestResult& result, const Json::String& expected,
if (!_threw) \
result_->addFailure(__FILE__, __LINE__, \
"expected exception thrown: " #expr); \
}
} while (0)

/// \brief Begin a fixture test case.
#define JSONTEST_FIXTURE(FixtureType, name) \
Expand Down
43 changes: 21 additions & 22 deletions src/test_lib_json/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1874,7 +1874,7 @@ JSONTEST_FIXTURE_LOCAL(ValueTest, CommentBefore) {
Json::String result = Json::writeString(wbuilder, val);
JSONTEST_ASSERT_STRING_EQUAL(expected, result);
Json::String res2 = val.toStyledString();
Json::String exp2 = "";
Json::String exp2;
exp2 += expected;
exp2 += "\n";
JSONTEST_ASSERT_STRING_EQUAL(exp2, res2);
Expand Down Expand Up @@ -2592,7 +2592,7 @@ JSONTEST_FIXTURE_LOCAL(StreamWriterTest, indentation) {
JSONTEST_FIXTURE_LOCAL(StreamWriterTest, writeZeroes) {
Json::String binary("hi", 3); // include trailing 0
JSONTEST_ASSERT_EQUAL(3, binary.length());
Json::String expected("\"hi\\u0000\""); // unicoded zero
Json::String expected(R"("hi\u0000")"); // unicoded zero
Json::StreamWriterBuilder b;
{
Json::Value root;
Expand Down Expand Up @@ -2866,7 +2866,7 @@ JSONTEST_FIXTURE_LOCAL(CharReaderTest, parseWithNoErrors) {
CharReaderPtr reader(b.newCharReader());
Json::String errs;
Json::Value root;
char const doc[] = "{ \"property\" : \"value\" }";
char const doc[] = R"({ "property" : "value" })";
bool ok = reader->parse(doc, doc + std::strlen(doc), &root, &errs);
JSONTEST_ASSERT(ok);
JSONTEST_ASSERT(errs.empty());
Expand Down Expand Up @@ -2914,14 +2914,14 @@ JSONTEST_FIXTURE_LOCAL(CharReaderTest, parseString) {
JSONTEST_ASSERT_EQUAL("", root[0]);
}
{
char const doc[] = "[\"\\u8A2a\"]";
char const doc[] = R"(["\u8A2a"])";
bool ok = reader->parse(doc, doc + std::strlen(doc), &root, &errs);
JSONTEST_ASSERT(ok);
JSONTEST_ASSERT(errs.empty());
JSONTEST_ASSERT_EQUAL(u8"\u8A2a", root[0].asString()); // "訪"
}
{
char const doc[] = "[ \"\\uD801\" ]";
char const doc[] = R"([ "\uD801" ])";
bool ok = reader->parse(doc, doc + std::strlen(doc), &root, &errs);
JSONTEST_ASSERT(!ok);
JSONTEST_ASSERT(errs == "* Line 1, Column 3\n"
Expand All @@ -2930,7 +2930,7 @@ JSONTEST_FIXTURE_LOCAL(CharReaderTest, parseString) {
"See Line 1, Column 10 for detail.\n");
}
{
char const doc[] = "[ \"\\uD801\\d1234\" ]";
char const doc[] = R"([ "\uD801\d1234" ])";
bool ok = reader->parse(doc, doc + std::strlen(doc), &root, &errs);
JSONTEST_ASSERT(!ok);
JSONTEST_ASSERT(errs == "* Line 1, Column 3\n"
Expand All @@ -2939,7 +2939,7 @@ JSONTEST_FIXTURE_LOCAL(CharReaderTest, parseString) {
"See Line 1, Column 12 for detail.\n");
}
{
char const doc[] = "[ \"\\ua3t@\" ]";
char const doc[] = R"([ "\ua3t@" ])";
bool ok = reader->parse(doc, doc + std::strlen(doc), &root, &errs);
JSONTEST_ASSERT(!ok);
JSONTEST_ASSERT(errs == "* Line 1, Column 3\n"
Expand All @@ -2948,7 +2948,7 @@ JSONTEST_FIXTURE_LOCAL(CharReaderTest, parseString) {
"See Line 1, Column 9 for detail.\n");
}
{
char const doc[] = "[ \"\\ua3t\" ]";
char const doc[] = R"([ "\ua3t" ])";
bool ok = reader->parse(doc, doc + std::strlen(doc), &root, &errs);
JSONTEST_ASSERT(!ok);
JSONTEST_ASSERT(
Expand All @@ -2960,7 +2960,7 @@ JSONTEST_FIXTURE_LOCAL(CharReaderTest, parseString) {
{
b.settings_["allowSingleQuotes"] = true;
CharReaderPtr charreader(b.newCharReader());
char const doc[] = "{'a': 'x\\ty', \"b\":'x\\\\y'}";
char const doc[] = R"({'a': 'x\ty', "b":'x\\y'})";
bool ok = charreader->parse(doc, doc + std::strlen(doc), &root, &errs);
JSONTEST_ASSERT(ok);
JSONTEST_ASSERT_STRING_EQUAL("", errs);
Expand Down Expand Up @@ -3007,15 +3007,15 @@ JSONTEST_FIXTURE_LOCAL(CharReaderTest, parseObjectWithErrors) {
Json::Value root;
Json::String errs;
{
char const doc[] = "{ \"property\" : \"value\" ";
char const doc[] = R"({ "property" : "value" )";
bool ok = reader->parse(doc, doc + std::strlen(doc), &root, &errs);
JSONTEST_ASSERT(!ok);
JSONTEST_ASSERT(errs == "* Line 1, Column 24\n"
" Missing ',' or '}' in object declaration\n");
JSONTEST_ASSERT_EQUAL("value", root["property"]);
}
{
char const doc[] = "{ \"property\" : \"value\" ,";
char const doc[] = R"({ "property" : "value" ,)";
bool ok = reader->parse(doc, doc + std::strlen(doc), &root, &errs);
JSONTEST_ASSERT(!ok);
JSONTEST_ASSERT(errs == "* Line 1, Column 25\n"
Expand All @@ -3038,7 +3038,7 @@ JSONTEST_FIXTURE_LOCAL(CharReaderTest, parseArrayWithErrors) {
JSONTEST_ASSERT_EQUAL("value", root[0]);
}
{
char const doc[] = "[ \"value1\" \"value2\" ]";
char const doc[] = R"([ "value1" "value2" ])";
bool ok = reader->parse(doc, doc + std::strlen(doc), &root, &errs);
JSONTEST_ASSERT(!ok);
JSONTEST_ASSERT(errs == "* Line 1, Column 12\n"
Expand All @@ -3052,7 +3052,7 @@ JSONTEST_FIXTURE_LOCAL(CharReaderTest, parseWithOneError) {
CharReaderPtr reader(b.newCharReader());
Json::String errs;
Json::Value root;
char const doc[] = "{ \"property\" :: \"value\" }";
char const doc[] = R"({ "property" :: "value" })";
bool ok = reader->parse(doc, doc + std::strlen(doc), &root, &errs);
JSONTEST_ASSERT(!ok);
JSONTEST_ASSERT(errs ==
Expand All @@ -3078,7 +3078,7 @@ JSONTEST_FIXTURE_LOCAL(CharReaderTest, parseWithDetailError) {
CharReaderPtr reader(b.newCharReader());
Json::String errs;
Json::Value root;
char const doc[] = "{ \"property\" : \"v\\alue\" }";
char const doc[] = R"({ "property" : "v\alue" })";
bool ok = reader->parse(doc, doc + std::strlen(doc), &root, &errs);
JSONTEST_ASSERT(!ok);
JSONTEST_ASSERT(errs ==
Expand All @@ -3089,7 +3089,7 @@ JSONTEST_FIXTURE_LOCAL(CharReaderTest, parseWithDetailError) {
JSONTEST_FIXTURE_LOCAL(CharReaderTest, parseWithStackLimit) {
Json::CharReaderBuilder b;
Json::Value root;
char const doc[] = "{ \"property\" : \"value\" }";
char const doc[] = R"({ "property" : "value" })";
{
b.settings_["stackLimit"] = 2;
CharReaderPtr reader(b.newCharReader());
Expand All @@ -3109,7 +3109,7 @@ JSONTEST_FIXTURE_LOCAL(CharReaderTest, parseWithStackLimit) {
}

JSONTEST_FIXTURE_LOCAL(CharReaderTest, testOperator) {
const std::string styled = "{ \"property\" : \"value\" }";
const std::string styled = R"({ "property" : "value" })";
std::istringstream iss(styled);
Json::Value root;
iss >> root;
Expand All @@ -3122,7 +3122,7 @@ JSONTEST_FIXTURE_LOCAL(CharReaderStrictModeTest, dupKeys) {
Json::CharReaderBuilder b;
Json::Value root;
char const doc[] =
"{ \"property\" : \"value\", \"key\" : \"val1\", \"key\" : \"val2\" }";
R"({ "property" : "value", "key" : "val1", "key" : "val2" })";
{
b.strictMode(&b.settings_);
CharReaderPtr reader(b.newCharReader());
Expand All @@ -3141,7 +3141,7 @@ JSONTEST_FIXTURE_LOCAL(CharReaderFailIfExtraTest, issue164) {
// This is interpreted as a string value followed by a colon.
Json::CharReaderBuilder b;
Json::Value root;
char const doc[] = " \"property\" : \"value\" }";
char const doc[] = R"( "property" : "value" })";
{
b.settings_["failIfExtra"] = false;
CharReaderPtr reader(b.newCharReader());
Expand Down Expand Up @@ -3445,8 +3445,7 @@ JSONTEST_FIXTURE_LOCAL(CharReaderAllowSpecialFloatsTest, issue209) {
Json::String errs;
CharReaderPtr reader(b.newCharReader());
{
char const doc[] =
"{\"a\":NaN,\"b\":Infinity,\"c\":-Infinity,\"d\":+Infinity}";
char const doc[] = R"({"a":NaN,"b":Infinity,"c":-Infinity,"d":+Infinity})";
bool ok = reader->parse(doc, doc + std::strlen(doc), &root, &errs);
JSONTEST_ASSERT(ok);
JSONTEST_ASSERT_STRING_EQUAL("", errs);
Expand Down Expand Up @@ -3497,7 +3496,7 @@ JSONTEST_FIXTURE_LOCAL(CharReaderAllowSpecialFloatsTest, issue209) {
}

{
char const doc[] = "{\"posInf\": +Infinity, \"NegInf\": -Infinity}";
char const doc[] = R"({"posInf": +Infinity, "NegInf": -Infinity})";
bool ok = reader->parse(doc, doc + std::strlen(doc), &root, &errs);
JSONTEST_ASSERT(ok);
JSONTEST_ASSERT_STRING_EQUAL("", errs);
Expand Down Expand Up @@ -3719,7 +3718,7 @@ JSONTEST_FIXTURE_LOCAL(IteratorTest, constness) {
for (; iter != value.end(); ++iter) {
out << *iter << ',';
}
Json::String expected = "\" 9\",\"10\",\"11\",";
Json::String expected = R"(" 9","10","11",)";
JSONTEST_ASSERT_STRING_EQUAL(expected, out.str());
}

Expand Down