Skip to content

Commit 1fc3de7

Browse files
committed
STYLE: Use auto for variable type matches the type of the initializer expression
This check is responsible for using the auto type specifier for variable declarations to improve code readability and maintainability. The auto type specifier will only be introduced in situations where the variable type matches the type of the initializer expression. In other words auto should deduce the same type that was originally spelled in the source SRCDIR=/Users/johnsonhj/src/jsoncpp/ #My local SRC BLDDIR=/Users/johnsonhj/src/jsoncpp/cmake-build-debug/ #My local BLD cd /Users/johnsonhj/src/jsoncpp/cmake-build-debug/ run-clang-tidy.py -extra-arg=-D__clang__ -checks=-*,modernize-use-auto -header-filter = .* -fix
1 parent cbeed7b commit 1fc3de7

File tree

6 files changed

+18
-18
lines changed

6 files changed

+18
-18
lines changed

src/jsontestrunner/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ static JSONCPP_STRING readInputTestFile(const char* path) {
5656
return JSONCPP_STRING("");
5757
fseek(file, 0, SEEK_END);
5858
long const size = ftell(file);
59-
unsigned long const usize = static_cast<unsigned long>(size);
59+
size_t const usize = static_cast<unsigned long>(size);
6060
fseek(file, 0, SEEK_SET);
6161
JSONCPP_STRING text;
6262
char* buffer = new char[size + 1];

src/lib_json/json_reader.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ bool Reader::decodeNumber(Token& token, Value& decoded) {
577577
Char c = *current++;
578578
if (c < '0' || c > '9')
579579
return decodeDouble(token, decoded);
580-
Value::UInt digit(static_cast<Value::UInt>(c - '0'));
580+
auto digit(static_cast<Value::UInt>(c - '0'));
581581
if (value >= threshold) {
582582
// We've hit or exceeded the max value divided by 10 (rounded down). If
583583
// a) we've only just touched the limit, b) this is the last digit, and
@@ -1569,7 +1569,7 @@ bool OurReader::decodeNumber(Token& token, Value& decoded) {
15691569
Char c = *current++;
15701570
if (c < '0' || c > '9')
15711571
return decodeDouble(token, decoded);
1572-
Value::UInt digit(static_cast<Value::UInt>(c - '0'));
1572+
auto digit(static_cast<Value::UInt>(c - '0'));
15731573
if (value >= threshold) {
15741574
// We've hit or exceeded the max value divided by 10 (rounded down). If
15751575
// a) we've only just touched the limit, b) this is the last digit, and
@@ -1611,7 +1611,7 @@ bool OurReader::decodeDouble(Token& token, Value& decoded) {
16111611
if (length < 0) {
16121612
return addError("Unable to parse token length", token);
16131613
}
1614-
size_t const ulength = static_cast<size_t>(length);
1614+
auto const ulength = static_cast<size_t>(length);
16151615

16161616
// Avoid using a string constant for the format control string given to
16171617
// sscanf, as this can cause hard to debug crashes on OS X. See here for more

src/lib_json/json_value.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -990,7 +990,7 @@ Value& Value::operator[](ArrayIndex index) {
990990
if (type_ == nullValue)
991991
*this = Value(arrayValue);
992992
CZString key(index);
993-
ObjectValues::iterator it = value_.map_->lower_bound(key);
993+
auto it = value_.map_->lower_bound(key);
994994
if (it != value_.map_->end() && (*it).first == key)
995995
return (*it).second;
996996

@@ -1113,7 +1113,7 @@ Value& Value::resolveReference(const char* key) {
11131113
*this = Value(objectValue);
11141114
CZString actualKey(key, static_cast<unsigned>(strlen(key)),
11151115
CZString::noDuplication); // NOTE!
1116-
ObjectValues::iterator it = value_.map_->lower_bound(actualKey);
1116+
auto it = value_.map_->lower_bound(actualKey);
11171117
if (it != value_.map_->end() && (*it).first == actualKey)
11181118
return (*it).second;
11191119

@@ -1132,7 +1132,7 @@ Value& Value::resolveReference(char const* key, char const* end) {
11321132
*this = Value(objectValue);
11331133
CZString actualKey(key, static_cast<unsigned>(end - key),
11341134
CZString::duplicateOnCopy);
1135-
ObjectValues::iterator it = value_.map_->lower_bound(actualKey);
1135+
auto it = value_.map_->lower_bound(actualKey);
11361136
if (it != value_.map_->end() && (*it).first == actualKey)
11371137
return (*it).second;
11381138

@@ -1226,7 +1226,7 @@ bool Value::removeMember(const char* begin, const char* end, Value* removed) {
12261226
}
12271227
CZString actualKey(begin, static_cast<unsigned>(end - begin),
12281228
CZString::noDuplication);
1229-
ObjectValues::iterator it = value_.map_->find(actualKey);
1229+
auto it = value_.map_->find(actualKey);
12301230
if (it == value_.map_->end())
12311231
return false;
12321232
if (removed)
@@ -1262,7 +1262,7 @@ bool Value::removeIndex(ArrayIndex index, Value* removed) {
12621262
return false;
12631263
}
12641264
CZString key(index);
1265-
ObjectValues::iterator it = value_.map_->find(key);
1265+
auto it = value_.map_->find(key);
12661266
if (it == value_.map_->end()) {
12671267
return false;
12681268
}
@@ -1276,7 +1276,7 @@ bool Value::removeIndex(ArrayIndex index, Value* removed) {
12761276
}
12771277
// erase the last one ("leftover")
12781278
CZString keyLast(oldSize - 1);
1279-
ObjectValues::iterator itLast = value_.map_->find(keyLast);
1279+
auto itLast = value_.map_->find(keyLast);
12801280
value_.map_->erase(itLast);
12811281
return true;
12821282
}
@@ -1608,7 +1608,7 @@ Path::Path(const JSONCPP_STRING& path,
16081608
void Path::makePath(const JSONCPP_STRING& path, const InArgs& in) {
16091609
const char* current = path.c_str();
16101610
const char* end = current + path.length();
1611-
InArgs::const_iterator itInArg = in.begin();
1611+
auto itInArg = in.begin();
16121612
while (current != end) {
16131613
if (*current == '[') {
16141614
++current;

src/lib_json/json_writer.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ JSONCPP_STRING valueToString(double value,
147147
(precisionType == PrecisionType::significantDigits) ? "%.*g" : "%.*f",
148148
precision, value);
149149
assert(len >= 0);
150-
size_t wouldPrint = static_cast<size_t>(len);
150+
auto wouldPrint = static_cast<size_t>(len);
151151
if (wouldPrint >= buffer.size()) {
152152
buffer.resize(wouldPrint + 1);
153153
continue;
@@ -409,7 +409,7 @@ void FastWriter::writeValue(const Value& value) {
409409
case objectValue: {
410410
Value::Members members(value.getMemberNames());
411411
document_ += '{';
412-
for (Value::Members::iterator it = members.begin(); it != members.end();
412+
for (auto it = members.begin(); it != members.end();
413413
++it) {
414414
const JSONCPP_STRING& name = *it;
415415
if (it != members.begin())
@@ -479,7 +479,7 @@ void StyledWriter::writeValue(const Value& value) {
479479
else {
480480
writeWithIndent("{");
481481
indent();
482-
Value::Members::iterator it = members.begin();
482+
auto it = members.begin();
483483
for (;;) {
484484
const JSONCPP_STRING& name = *it;
485485
const Value& childValue = value[name];
@@ -699,7 +699,7 @@ void StyledStreamWriter::writeValue(const Value& value) {
699699
else {
700700
writeWithIndent("{");
701701
indent();
702-
Value::Members::iterator it = members.begin();
702+
auto it = members.begin();
703703
for (;;) {
704704
const JSONCPP_STRING& name = *it;
705705
const Value& childValue = value[name];
@@ -979,7 +979,7 @@ void BuiltStyledStreamWriter::writeValue(Value const& value) {
979979
else {
980980
writeWithIndent("{");
981981
indent();
982-
Value::Members::iterator it = members.begin();
982+
auto it = members.begin();
983983
for (;;) {
984984
JSONCPP_STRING const& name = *it;
985985
Value const& childValue = value[name];

src/test_lib_json/jsontest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ bool Runner::runAllTest(bool printSummary) const {
278278
}
279279

280280
if (printSummary) {
281-
unsigned int failedCount = static_cast<unsigned int>(failures.size());
281+
auto failedCount = static_cast<unsigned int>(failures.size());
282282
unsigned int passedCount = count - failedCount;
283283
printf("%u/%u tests passed (%u failure(s))\n", passedCount, count,
284284
failedCount);

src/test_lib_json/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1036,7 +1036,7 @@ JSONTEST_FIXTURE(ValueTest, integers) {
10361036
normalizeFloatingPointStr(JsonTest::ToJsonString(val.asString())));
10371037

10381038
// 10^19
1039-
const Json::UInt64 ten_to_19 = static_cast<Json::UInt64>(1e19);
1039+
const auto ten_to_19 = static_cast<Json::UInt64>(1e19);
10401040
val = Json::Value(Json::UInt64(ten_to_19));
10411041

10421042
JSONTEST_ASSERT_EQUAL(Json::uintValue, val.type());

0 commit comments

Comments
 (0)