Skip to content

Commit c4f162e

Browse files
committed
Revert "clang-tidy fixes again (#1155)"
This reverts commit 90ca694.
1 parent 8b20b7a commit c4f162e

File tree

7 files changed

+53
-40
lines changed

7 files changed

+53
-40
lines changed

include/json/assertions.h

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,19 @@
2121

2222
// @todo <= add detail about condition in exception
2323
#define JSON_ASSERT(condition) \
24-
do { \
24+
{ \
2525
if (!(condition)) { \
2626
Json::throwLogicError("assert json failed"); \
2727
} \
28-
} while (0)
28+
}
2929

3030
#define JSON_FAIL_MESSAGE(message) \
31-
do { \
31+
{ \
3232
OStringStream oss; \
3333
oss << message; \
3434
Json::throwLogicError(oss.str()); \
3535
abort(); \
36-
} while (0)
36+
}
3737

3838
#else // JSON_USE_EXCEPTION
3939

@@ -52,10 +52,8 @@
5252
#endif
5353

5454
#define JSON_ASSERT_MESSAGE(condition, message) \
55-
do { \
56-
if (!(condition)) { \
57-
JSON_FAIL_MESSAGE(message); \
58-
} \
59-
} while (0)
55+
if (!(condition)) { \
56+
JSON_FAIL_MESSAGE(message); \
57+
}
6058

6159
#endif // JSON_ASSERTIONS_H_INCLUDED

include/json/config.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,20 @@ extern JSON_API int msvc_pre1900_c99_snprintf(char* outBuf, size_t size,
7474
// C++11 should be used directly in JSONCPP.
7575
#define JSONCPP_OVERRIDE override
7676

77+
#if __cplusplus >= 201103L
78+
#define JSONCPP_NOEXCEPT noexcept
79+
#define JSONCPP_OP_EXPLICIT explicit
80+
#elif defined(_MSC_VER) && _MSC_VER < 1900
81+
#define JSONCPP_NOEXCEPT throw()
82+
#define JSONCPP_OP_EXPLICIT explicit
83+
#elif defined(_MSC_VER) && _MSC_VER >= 1900
84+
#define JSONCPP_NOEXCEPT noexcept
85+
#define JSONCPP_OP_EXPLICIT explicit
86+
#else
87+
#define JSONCPP_NOEXCEPT throw()
88+
#define JSONCPP_OP_EXPLICIT
89+
#endif
90+
7791
#ifdef __clang__
7892
#if __has_extension(attribute_deprecated_with_message)
7993
#define JSONCPP_DEPRECATED(message) __attribute__((deprecated(message)))

include/json/value.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ namespace Json {
6767
class JSON_API Exception : public std::exception {
6868
public:
6969
Exception(String msg);
70-
~Exception() noexcept override;
71-
char const* what() const noexcept override;
70+
~Exception() JSONCPP_NOEXCEPT override;
71+
char const* what() const JSONCPP_NOEXCEPT override;
7272

7373
protected:
7474
String msg_;
@@ -421,7 +421,7 @@ class JSON_API Value {
421421
bool empty() const;
422422

423423
/// Return !isNull()
424-
explicit operator bool() const;
424+
JSONCPP_OP_EXPLICIT operator bool() const;
425425

426426
/// Remove all object members and array elements.
427427
/// \pre type() is arrayValue, objectValue, or nullValue

src/jsontestrunner/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ static void printValueTree(FILE* fout, Json::Value& value,
111111
Json::Value::Members members(value.getMemberNames());
112112
std::sort(members.begin(), members.end());
113113
Json::String suffix = *(path.end() - 1) == '.' ? "" : ".";
114-
for (const auto& name : members) {
114+
for (auto name : members) {
115115
printValueTree(fout, value[name], path + suffix + name);
116116
}
117117
} break;

src/lib_json/json_value.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,8 @@ namespace Json {
200200

201201
#if JSON_USE_EXCEPTION
202202
Exception::Exception(String msg) : msg_(std::move(msg)) {}
203-
Exception::~Exception() noexcept = default;
204-
char const* Exception::what() const noexcept { return msg_.c_str(); }
203+
Exception::~Exception() JSONCPP_NOEXCEPT = default;
204+
char const* Exception::what() const JSONCPP_NOEXCEPT { return msg_.c_str(); }
205205
RuntimeError::RuntimeError(String const& msg) : Exception(msg) {}
206206
LogicError::LogicError(String const& msg) : Exception(msg) {}
207207
JSONCPP_NORETURN void throwRuntimeError(String const& msg) {

src/test_lib_json/jsontest.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -207,15 +207,15 @@ TestResult& checkStringEqual(TestResult& result, const Json::String& expected,
207207
/// The predicate may do other assertions and be a member function of the
208208
/// fixture.
209209
#define JSONTEST_ASSERT_PRED(expr) \
210-
do { \
210+
{ \
211211
JsonTest::PredicateContext _minitest_Context = { \
212212
result_->predicateId_, __FILE__, __LINE__, #expr, NULL, NULL}; \
213213
result_->predicateStackTail_->next_ = &_minitest_Context; \
214214
result_->predicateId_ += 1; \
215215
result_->predicateStackTail_ = &_minitest_Context; \
216216
(expr); \
217217
result_->popPredicateContext(); \
218-
} while (0)
218+
}
219219

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

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

245245
/// \brief Begin a fixture test case.
246246
#define JSONTEST_FIXTURE(FixtureType, name) \

src/test_lib_json/main.cpp

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1874,7 +1874,7 @@ JSONTEST_FIXTURE_LOCAL(ValueTest, CommentBefore) {
18741874
Json::String result = Json::writeString(wbuilder, val);
18751875
JSONTEST_ASSERT_STRING_EQUAL(expected, result);
18761876
Json::String res2 = val.toStyledString();
1877-
Json::String exp2;
1877+
Json::String exp2 = "";
18781878
exp2 += expected;
18791879
exp2 += "\n";
18801880
JSONTEST_ASSERT_STRING_EQUAL(exp2, res2);
@@ -2592,7 +2592,7 @@ JSONTEST_FIXTURE_LOCAL(StreamWriterTest, indentation) {
25922592
JSONTEST_FIXTURE_LOCAL(StreamWriterTest, writeZeroes) {
25932593
Json::String binary("hi", 3); // include trailing 0
25942594
JSONTEST_ASSERT_EQUAL(3, binary.length());
2595-
Json::String expected(R"("hi\u0000")"); // unicoded zero
2595+
Json::String expected("\"hi\\u0000\""); // unicoded zero
25962596
Json::StreamWriterBuilder b;
25972597
{
25982598
Json::Value root;
@@ -2866,7 +2866,7 @@ JSONTEST_FIXTURE_LOCAL(CharReaderTest, parseWithNoErrors) {
28662866
CharReaderPtr reader(b.newCharReader());
28672867
Json::String errs;
28682868
Json::Value root;
2869-
char const doc[] = R"({ "property" : "value" })";
2869+
char const doc[] = "{ \"property\" : \"value\" }";
28702870
bool ok = reader->parse(doc, doc + std::strlen(doc), &root, &errs);
28712871
JSONTEST_ASSERT(ok);
28722872
JSONTEST_ASSERT(errs.empty());
@@ -2914,14 +2914,14 @@ JSONTEST_FIXTURE_LOCAL(CharReaderTest, parseString) {
29142914
JSONTEST_ASSERT_EQUAL("", root[0]);
29152915
}
29162916
{
2917-
char const doc[] = R"(["\u8A2a"])";
2917+
char const doc[] = "[\"\\u8A2a\"]";
29182918
bool ok = reader->parse(doc, doc + std::strlen(doc), &root, &errs);
29192919
JSONTEST_ASSERT(ok);
29202920
JSONTEST_ASSERT(errs.empty());
29212921
JSONTEST_ASSERT_EQUAL(u8"\u8A2a", root[0].asString()); // "訪"
29222922
}
29232923
{
2924-
char const doc[] = R"([ "\uD801" ])";
2924+
char const doc[] = "[ \"\\uD801\" ]";
29252925
bool ok = reader->parse(doc, doc + std::strlen(doc), &root, &errs);
29262926
JSONTEST_ASSERT(!ok);
29272927
JSONTEST_ASSERT(errs == "* Line 1, Column 3\n"
@@ -2930,7 +2930,7 @@ JSONTEST_FIXTURE_LOCAL(CharReaderTest, parseString) {
29302930
"See Line 1, Column 10 for detail.\n");
29312931
}
29322932
{
2933-
char const doc[] = R"([ "\uD801\d1234" ])";
2933+
char const doc[] = "[ \"\\uD801\\d1234\" ]";
29342934
bool ok = reader->parse(doc, doc + std::strlen(doc), &root, &errs);
29352935
JSONTEST_ASSERT(!ok);
29362936
JSONTEST_ASSERT(errs == "* Line 1, Column 3\n"
@@ -2939,7 +2939,7 @@ JSONTEST_FIXTURE_LOCAL(CharReaderTest, parseString) {
29392939
"See Line 1, Column 12 for detail.\n");
29402940
}
29412941
{
2942-
char const doc[] = R"([ "\ua3t@" ])";
2942+
char const doc[] = "[ \"\\ua3t@\" ]";
29432943
bool ok = reader->parse(doc, doc + std::strlen(doc), &root, &errs);
29442944
JSONTEST_ASSERT(!ok);
29452945
JSONTEST_ASSERT(errs == "* Line 1, Column 3\n"
@@ -2948,7 +2948,7 @@ JSONTEST_FIXTURE_LOCAL(CharReaderTest, parseString) {
29482948
"See Line 1, Column 9 for detail.\n");
29492949
}
29502950
{
2951-
char const doc[] = R"([ "\ua3t" ])";
2951+
char const doc[] = "[ \"\\ua3t\" ]";
29522952
bool ok = reader->parse(doc, doc + std::strlen(doc), &root, &errs);
29532953
JSONTEST_ASSERT(!ok);
29542954
JSONTEST_ASSERT(
@@ -2960,7 +2960,7 @@ JSONTEST_FIXTURE_LOCAL(CharReaderTest, parseString) {
29602960
{
29612961
b.settings_["allowSingleQuotes"] = true;
29622962
CharReaderPtr charreader(b.newCharReader());
2963-
char const doc[] = R"({'a': 'x\ty', "b":'x\\y'})";
2963+
char const doc[] = "{'a': 'x\\ty', \"b\":'x\\\\y'}";
29642964
bool ok = charreader->parse(doc, doc + std::strlen(doc), &root, &errs);
29652965
JSONTEST_ASSERT(ok);
29662966
JSONTEST_ASSERT_STRING_EQUAL("", errs);
@@ -3007,15 +3007,15 @@ JSONTEST_FIXTURE_LOCAL(CharReaderTest, parseObjectWithErrors) {
30073007
Json::Value root;
30083008
Json::String errs;
30093009
{
3010-
char const doc[] = R"({ "property" : "value" )";
3010+
char const doc[] = "{ \"property\" : \"value\" ";
30113011
bool ok = reader->parse(doc, doc + std::strlen(doc), &root, &errs);
30123012
JSONTEST_ASSERT(!ok);
30133013
JSONTEST_ASSERT(errs == "* Line 1, Column 24\n"
30143014
" Missing ',' or '}' in object declaration\n");
30153015
JSONTEST_ASSERT_EQUAL("value", root["property"]);
30163016
}
30173017
{
3018-
char const doc[] = R"({ "property" : "value" ,)";
3018+
char const doc[] = "{ \"property\" : \"value\" ,";
30193019
bool ok = reader->parse(doc, doc + std::strlen(doc), &root, &errs);
30203020
JSONTEST_ASSERT(!ok);
30213021
JSONTEST_ASSERT(errs == "* Line 1, Column 25\n"
@@ -3038,7 +3038,7 @@ JSONTEST_FIXTURE_LOCAL(CharReaderTest, parseArrayWithErrors) {
30383038
JSONTEST_ASSERT_EQUAL("value", root[0]);
30393039
}
30403040
{
3041-
char const doc[] = R"([ "value1" "value2" ])";
3041+
char const doc[] = "[ \"value1\" \"value2\" ]";
30423042
bool ok = reader->parse(doc, doc + std::strlen(doc), &root, &errs);
30433043
JSONTEST_ASSERT(!ok);
30443044
JSONTEST_ASSERT(errs == "* Line 1, Column 12\n"
@@ -3052,7 +3052,7 @@ JSONTEST_FIXTURE_LOCAL(CharReaderTest, parseWithOneError) {
30523052
CharReaderPtr reader(b.newCharReader());
30533053
Json::String errs;
30543054
Json::Value root;
3055-
char const doc[] = R"({ "property" :: "value" })";
3055+
char const doc[] = "{ \"property\" :: \"value\" }";
30563056
bool ok = reader->parse(doc, doc + std::strlen(doc), &root, &errs);
30573057
JSONTEST_ASSERT(!ok);
30583058
JSONTEST_ASSERT(errs ==
@@ -3078,7 +3078,7 @@ JSONTEST_FIXTURE_LOCAL(CharReaderTest, parseWithDetailError) {
30783078
CharReaderPtr reader(b.newCharReader());
30793079
Json::String errs;
30803080
Json::Value root;
3081-
char const doc[] = R"({ "property" : "v\alue" })";
3081+
char const doc[] = "{ \"property\" : \"v\\alue\" }";
30823082
bool ok = reader->parse(doc, doc + std::strlen(doc), &root, &errs);
30833083
JSONTEST_ASSERT(!ok);
30843084
JSONTEST_ASSERT(errs ==
@@ -3089,7 +3089,7 @@ JSONTEST_FIXTURE_LOCAL(CharReaderTest, parseWithDetailError) {
30893089
JSONTEST_FIXTURE_LOCAL(CharReaderTest, parseWithStackLimit) {
30903090
Json::CharReaderBuilder b;
30913091
Json::Value root;
3092-
char const doc[] = R"({ "property" : "value" })";
3092+
char const doc[] = "{ \"property\" : \"value\" }";
30933093
{
30943094
b.settings_["stackLimit"] = 2;
30953095
CharReaderPtr reader(b.newCharReader());
@@ -3109,7 +3109,7 @@ JSONTEST_FIXTURE_LOCAL(CharReaderTest, parseWithStackLimit) {
31093109
}
31103110

31113111
JSONTEST_FIXTURE_LOCAL(CharReaderTest, testOperator) {
3112-
const std::string styled = R"({ "property" : "value" })";
3112+
const std::string styled = "{ \"property\" : \"value\" }";
31133113
std::istringstream iss(styled);
31143114
Json::Value root;
31153115
iss >> root;
@@ -3122,7 +3122,7 @@ JSONTEST_FIXTURE_LOCAL(CharReaderStrictModeTest, dupKeys) {
31223122
Json::CharReaderBuilder b;
31233123
Json::Value root;
31243124
char const doc[] =
3125-
R"({ "property" : "value", "key" : "val1", "key" : "val2" })";
3125+
"{ \"property\" : \"value\", \"key\" : \"val1\", \"key\" : \"val2\" }";
31263126
{
31273127
b.strictMode(&b.settings_);
31283128
CharReaderPtr reader(b.newCharReader());
@@ -3141,7 +3141,7 @@ JSONTEST_FIXTURE_LOCAL(CharReaderFailIfExtraTest, issue164) {
31413141
// This is interpreted as a string value followed by a colon.
31423142
Json::CharReaderBuilder b;
31433143
Json::Value root;
3144-
char const doc[] = R"( "property" : "value" })";
3144+
char const doc[] = " \"property\" : \"value\" }";
31453145
{
31463146
b.settings_["failIfExtra"] = false;
31473147
CharReaderPtr reader(b.newCharReader());
@@ -3445,7 +3445,8 @@ JSONTEST_FIXTURE_LOCAL(CharReaderAllowSpecialFloatsTest, issue209) {
34453445
Json::String errs;
34463446
CharReaderPtr reader(b.newCharReader());
34473447
{
3448-
char const doc[] = R"({"a":NaN,"b":Infinity,"c":-Infinity,"d":+Infinity})";
3448+
char const doc[] =
3449+
"{\"a\":NaN,\"b\":Infinity,\"c\":-Infinity,\"d\":+Infinity}";
34493450
bool ok = reader->parse(doc, doc + std::strlen(doc), &root, &errs);
34503451
JSONTEST_ASSERT(ok);
34513452
JSONTEST_ASSERT_STRING_EQUAL("", errs);
@@ -3496,7 +3497,7 @@ JSONTEST_FIXTURE_LOCAL(CharReaderAllowSpecialFloatsTest, issue209) {
34963497
}
34973498

34983499
{
3499-
char const doc[] = R"({"posInf": +Infinity, "NegInf": -Infinity})";
3500+
char const doc[] = "{\"posInf\": +Infinity, \"NegInf\": -Infinity}";
35003501
bool ok = reader->parse(doc, doc + std::strlen(doc), &root, &errs);
35013502
JSONTEST_ASSERT(ok);
35023503
JSONTEST_ASSERT_STRING_EQUAL("", errs);
@@ -3718,7 +3719,7 @@ JSONTEST_FIXTURE_LOCAL(IteratorTest, constness) {
37183719
for (; iter != value.end(); ++iter) {
37193720
out << *iter << ',';
37203721
}
3721-
Json::String expected = R"(" 9","10","11",)";
3722+
Json::String expected = "\" 9\",\"10\",\"11\",";
37223723
JSONTEST_ASSERT_STRING_EQUAL(expected, out.str());
37233724
}
37243725

0 commit comments

Comments
 (0)