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
This commit is contained in:
Hans Johnson 2019-01-14 17:09:15 -06:00 committed by Hans Johnson
parent cbeed7b076
commit 1fc3de7ca1
6 changed files with 18 additions and 18 deletions

View File

@ -56,7 +56,7 @@ static JSONCPP_STRING readInputTestFile(const char* path) {
return JSONCPP_STRING("");
fseek(file, 0, SEEK_END);
long const size = ftell(file);
unsigned long const usize = static_cast<unsigned long>(size);
size_t const usize = static_cast<unsigned long>(size);
fseek(file, 0, SEEK_SET);
JSONCPP_STRING text;
char* buffer = new char[size + 1];

View File

@ -577,7 +577,7 @@ bool Reader::decodeNumber(Token& token, Value& decoded) {
Char c = *current++;
if (c < '0' || c > '9')
return decodeDouble(token, decoded);
Value::UInt digit(static_cast<Value::UInt>(c - '0'));
auto digit(static_cast<Value::UInt>(c - '0'));
if (value >= threshold) {
// We've hit or exceeded the max value divided by 10 (rounded down). If
// 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) {
Char c = *current++;
if (c < '0' || c > '9')
return decodeDouble(token, decoded);
Value::UInt digit(static_cast<Value::UInt>(c - '0'));
auto digit(static_cast<Value::UInt>(c - '0'));
if (value >= threshold) {
// We've hit or exceeded the max value divided by 10 (rounded down). If
// 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) {
if (length < 0) {
return addError("Unable to parse token length", token);
}
size_t const ulength = static_cast<size_t>(length);
auto const ulength = static_cast<size_t>(length);
// Avoid using a string constant for the format control string given to
// sscanf, as this can cause hard to debug crashes on OS X. See here for more

View File

@ -990,7 +990,7 @@ Value& Value::operator[](ArrayIndex index) {
if (type_ == nullValue)
*this = Value(arrayValue);
CZString key(index);
ObjectValues::iterator it = value_.map_->lower_bound(key);
auto it = value_.map_->lower_bound(key);
if (it != value_.map_->end() && (*it).first == key)
return (*it).second;
@ -1113,7 +1113,7 @@ Value& Value::resolveReference(const char* key) {
*this = Value(objectValue);
CZString actualKey(key, static_cast<unsigned>(strlen(key)),
CZString::noDuplication); // NOTE!
ObjectValues::iterator it = value_.map_->lower_bound(actualKey);
auto it = value_.map_->lower_bound(actualKey);
if (it != value_.map_->end() && (*it).first == actualKey)
return (*it).second;
@ -1132,7 +1132,7 @@ Value& Value::resolveReference(char const* key, char const* end) {
*this = Value(objectValue);
CZString actualKey(key, static_cast<unsigned>(end - key),
CZString::duplicateOnCopy);
ObjectValues::iterator it = value_.map_->lower_bound(actualKey);
auto it = value_.map_->lower_bound(actualKey);
if (it != value_.map_->end() && (*it).first == actualKey)
return (*it).second;
@ -1226,7 +1226,7 @@ bool Value::removeMember(const char* begin, const char* end, Value* removed) {
}
CZString actualKey(begin, static_cast<unsigned>(end - begin),
CZString::noDuplication);
ObjectValues::iterator it = value_.map_->find(actualKey);
auto it = value_.map_->find(actualKey);
if (it == value_.map_->end())
return false;
if (removed)
@ -1262,7 +1262,7 @@ bool Value::removeIndex(ArrayIndex index, Value* removed) {
return false;
}
CZString key(index);
ObjectValues::iterator it = value_.map_->find(key);
auto it = value_.map_->find(key);
if (it == value_.map_->end()) {
return false;
}
@ -1276,7 +1276,7 @@ bool Value::removeIndex(ArrayIndex index, Value* removed) {
}
// erase the last one ("leftover")
CZString keyLast(oldSize - 1);
ObjectValues::iterator itLast = value_.map_->find(keyLast);
auto itLast = value_.map_->find(keyLast);
value_.map_->erase(itLast);
return true;
}
@ -1608,7 +1608,7 @@ Path::Path(const JSONCPP_STRING& path,
void Path::makePath(const JSONCPP_STRING& path, const InArgs& in) {
const char* current = path.c_str();
const char* end = current + path.length();
InArgs::const_iterator itInArg = in.begin();
auto itInArg = in.begin();
while (current != end) {
if (*current == '[') {
++current;

View File

@ -147,7 +147,7 @@ JSONCPP_STRING valueToString(double value,
(precisionType == PrecisionType::significantDigits) ? "%.*g" : "%.*f",
precision, value);
assert(len >= 0);
size_t wouldPrint = static_cast<size_t>(len);
auto wouldPrint = static_cast<size_t>(len);
if (wouldPrint >= buffer.size()) {
buffer.resize(wouldPrint + 1);
continue;
@ -409,7 +409,7 @@ void FastWriter::writeValue(const Value& value) {
case objectValue: {
Value::Members members(value.getMemberNames());
document_ += '{';
for (Value::Members::iterator it = members.begin(); it != members.end();
for (auto it = members.begin(); it != members.end();
++it) {
const JSONCPP_STRING& name = *it;
if (it != members.begin())
@ -479,7 +479,7 @@ void StyledWriter::writeValue(const Value& value) {
else {
writeWithIndent("{");
indent();
Value::Members::iterator it = members.begin();
auto it = members.begin();
for (;;) {
const JSONCPP_STRING& name = *it;
const Value& childValue = value[name];
@ -699,7 +699,7 @@ void StyledStreamWriter::writeValue(const Value& value) {
else {
writeWithIndent("{");
indent();
Value::Members::iterator it = members.begin();
auto it = members.begin();
for (;;) {
const JSONCPP_STRING& name = *it;
const Value& childValue = value[name];
@ -979,7 +979,7 @@ void BuiltStyledStreamWriter::writeValue(Value const& value) {
else {
writeWithIndent("{");
indent();
Value::Members::iterator it = members.begin();
auto it = members.begin();
for (;;) {
JSONCPP_STRING const& name = *it;
Value const& childValue = value[name];

View File

@ -278,7 +278,7 @@ bool Runner::runAllTest(bool printSummary) const {
}
if (printSummary) {
unsigned int failedCount = static_cast<unsigned int>(failures.size());
auto failedCount = static_cast<unsigned int>(failures.size());
unsigned int passedCount = count - failedCount;
printf("%u/%u tests passed (%u failure(s))\n", passedCount, count,
failedCount);

View File

@ -1036,7 +1036,7 @@ JSONTEST_FIXTURE(ValueTest, integers) {
normalizeFloatingPointStr(JsonTest::ToJsonString(val.asString())));
// 10^19
const Json::UInt64 ten_to_19 = static_cast<Json::UInt64>(1e19);
const auto ten_to_19 = static_cast<Json::UInt64>(1e19);
val = Json::Value(Json::UInt64(ten_to_19));
JSONTEST_ASSERT_EQUAL(Json::uintValue, val.type());