Skip to content

Commit 2983f5a

Browse files
authored
Run Clang-tidy with modernize-use-auto (open-source-parsers#1077)
* Run clang-tidy modify with modernize-use-auto * Use using instead of typedef
1 parent a0bd9ad commit 2983f5a

File tree

14 files changed

+62
-61
lines changed

14 files changed

+62
-61
lines changed

.clang-tidy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
Checks: 'google-readability-casting,modernize-use-default-member-init,modernize-use-using,readability-redundant-member-init'
2+
Checks: 'google-readability-casting,modernize-use-default-member-init,modernize-use-using,modernize-use-auto,readability-redundant-member-init'
33
WarningsAsErrors: ''
44
HeaderFilterRegex: ''
55
AnalyzeTemporaryDtors: false

example/readFromString/readFromString.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*/
1212
int main() {
1313
const std::string rawJson = R"({"Age": 20, "Name": "colin"})";
14-
const int rawJsonLength = static_cast<int>(rawJson.length());
14+
const auto rawJsonLength = static_cast<int>(rawJson.length());
1515
constexpr bool shouldUseOldWay = false;
1616
JSONCPP_STRING err;
1717
Json::Value root;

include/json/config.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -119,23 +119,23 @@ extern JSON_API int msvc_pre1900_c99_snprintf(char* outBuf, size_t size,
119119
#endif // if !defined(JSON_IS_AMALGAMATION)
120120

121121
namespace Json {
122-
typedef int Int;
123-
typedef unsigned int UInt;
122+
using Int = int;
123+
using UInt = unsigned int;
124124
#if defined(JSON_NO_INT64)
125-
typedef int LargestInt;
126-
typedef unsigned int LargestUInt;
125+
using LargestInt = int;
126+
using LargestUInt = unsigned int;
127127
#undef JSON_HAS_INT64
128128
#else // if defined(JSON_NO_INT64)
129129
// For Microsoft Visual use specific types as long long is not supported
130130
#if defined(_MSC_VER) // Microsoft Visual Studio
131-
typedef __int64 Int64;
132-
typedef unsigned __int64 UInt64;
131+
using Int64 = __int64;
132+
using UInt64 = unsigned __int64;
133133
#else // if defined(_MSC_VER) // Other platforms, use long long
134-
typedef int64_t Int64;
135-
typedef uint64_t UInt64;
134+
using Int64 = int64_t;
135+
using UInt64 = uint64_t;
136136
#endif // if defined(_MSC_VER)
137-
typedef Int64 LargestInt;
138-
typedef UInt64 LargestUInt;
137+
using LargestInt = Int64;
138+
using LargestUInt = UInt64;
139139
#define JSON_HAS_INT64
140140
#endif // if defined(JSON_NO_INT64)
141141

include/json/forwards.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class CharReaderBuilder;
2929
class Features;
3030

3131
// value.h
32-
typedef unsigned int ArrayIndex;
32+
using ArrayIndex = unsigned int;
3333
class StaticString;
3434
class Path;
3535
class PathArgument;

include/json/reader.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ namespace Json {
3636
class JSONCPP_DEPRECATED(
3737
"Use CharReader and CharReaderBuilder instead.") JSON_API Reader {
3838
public:
39-
typedef char Char;
40-
typedef const Char* Location;
39+
using Char = char;
40+
using Location = const Char*;
4141

4242
/** \brief An error tagged with where in the JSON text it was encountered.
4343
*
@@ -187,7 +187,7 @@ class JSONCPP_DEPRECATED(
187187
Location extra_;
188188
};
189189

190-
typedef std::deque<ErrorInfo> Errors;
190+
using Errors = std::deque<ErrorInfo>;
191191

192192
bool readToken(Token& token);
193193
void skipSpaces();
@@ -226,7 +226,7 @@ class JSONCPP_DEPRECATED(
226226
static bool containsNewLine(Location begin, Location end);
227227
static String normalizeEOL(Location begin, Location end);
228228

229-
typedef std::stack<Value*> Nodes;
229+
using Nodes = std::stack<Value*>;
230230
Nodes nodes_;
231231
Errors errors_;
232232
String document_;

include/json/value.h

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -176,21 +176,21 @@ class JSON_API Value {
176176
friend class ValueIteratorBase;
177177

178178
public:
179-
typedef std::vector<String> Members;
180-
typedef ValueIterator iterator;
181-
typedef ValueConstIterator const_iterator;
182-
typedef Json::UInt UInt;
183-
typedef Json::Int Int;
179+
using Members = std::vector<String>;
180+
using iterator = ValueIterator;
181+
using const_iterator = ValueConstIterator;
182+
using UInt = Json::UInt;
183+
using Int = Json::Int;
184184
#if defined(JSON_HAS_INT64)
185-
typedef Json::UInt64 UInt64;
186-
typedef Json::Int64 Int64;
185+
using UInt64 = Json::UInt64;
186+
using Int64 = Json::Int64;
187187
#endif // defined(JSON_HAS_INT64)
188-
typedef Json::LargestInt LargestInt;
189-
typedef Json::LargestUInt LargestUInt;
190-
typedef Json::ArrayIndex ArrayIndex;
188+
using LargestInt = Json::LargestInt;
189+
using LargestUInt = Json::LargestUInt;
190+
using ArrayIndex = Json::ArrayIndex;
191191

192192
// Required for boost integration, e. g. BOOST_TEST
193-
typedef std::string value_type;
193+
using value_type = std::string;
194194

195195
#if JSON_USE_NULLREF
196196
// Binary compatibility kludges, do not use.
@@ -710,8 +710,8 @@ class JSON_API Path {
710710
Value& make(Value& root) const;
711711

712712
private:
713-
typedef std::vector<const PathArgument*> InArgs;
714-
typedef std::vector<PathArgument> Args;
713+
using InArgs = std::vector<const PathArgument*>;
714+
using Args = std::vector<PathArgument>;
715715

716716
void makePath(const String& path, const InArgs& in);
717717
void addPathInArg(const String& path, const InArgs& in,
@@ -726,10 +726,10 @@ class JSON_API Path {
726726
*/
727727
class JSON_API ValueIteratorBase {
728728
public:
729-
typedef std::bidirectional_iterator_tag iterator_category;
730-
typedef unsigned int size_t;
731-
typedef int difference_type;
732-
typedef ValueIteratorBase SelfType;
729+
using iterator_category = std::bidirectional_iterator_tag;
730+
using size_t = unsigned int;
731+
using difference_type = int;
732+
using SelfType = ValueIteratorBase;
733733

734734
bool operator==(const SelfType& other) const { return isEqual(other); }
735735

@@ -802,12 +802,12 @@ class JSON_API ValueConstIterator : public ValueIteratorBase {
802802
friend class Value;
803803

804804
public:
805-
typedef const Value value_type;
805+
using value_type = const Value;
806806
// typedef unsigned int size_t;
807807
// typedef int difference_type;
808-
typedef const Value& reference;
809-
typedef const Value* pointer;
810-
typedef ValueConstIterator SelfType;
808+
using reference = const Value&;
809+
using pointer = const Value*;
810+
using SelfType = ValueConstIterator;
811811

812812
ValueConstIterator();
813813
ValueConstIterator(ValueIterator const& other);
@@ -853,12 +853,12 @@ class JSON_API ValueIterator : public ValueIteratorBase {
853853
friend class Value;
854854

855855
public:
856-
typedef Value value_type;
857-
typedef unsigned int size_t;
858-
typedef int difference_type;
859-
typedef Value& reference;
860-
typedef Value* pointer;
861-
typedef ValueIterator SelfType;
856+
using value_type = Value;
857+
using size_t = unsigned int;
858+
using difference_type = int;
859+
using reference = Value&;
860+
using pointer = Value*;
861+
using SelfType = ValueIterator;
862862

863863
ValueIterator();
864864
explicit ValueIterator(const ValueConstIterator& other);

include/json/writer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ class JSONCPP_DEPRECATED("Use StreamWriterBuilder instead") JSON_API
252252
static bool hasCommentForValue(const Value& value);
253253
static String normalizeEOL(const String& text);
254254

255-
typedef std::vector<String> ChildValues;
255+
using ChildValues = std::vector<String>;
256256

257257
ChildValues childValues_;
258258
String document_;
@@ -326,7 +326,7 @@ class JSONCPP_DEPRECATED("Use StreamWriterBuilder instead") JSON_API
326326
static bool hasCommentForValue(const Value& value);
327327
static String normalizeEOL(const String& text);
328328

329-
typedef std::vector<String> ChildValues;
329+
using ChildValues = std::vector<String>;
330330

331331
ChildValues childValues_;
332332
OStream* document_;

src/jsontestrunner/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ static Json::String readInputTestFile(const char* path) {
5858
return "";
5959
fseek(file, 0, SEEK_END);
6060
long const size = ftell(file);
61-
size_t const usize = static_cast<unsigned long>(size);
61+
const auto usize = static_cast<size_t>(size);
6262
fseek(file, 0, SEEK_SET);
6363
char* buffer = new char[size + 1];
6464
buffer[size] = 0;

src/lib_json/json_reader.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ namespace Json {
5454
#if __cplusplus >= 201103L || (defined(_CPPLIB_VER) && _CPPLIB_VER >= 520)
5555
using CharReaderPtr = std::unique_ptr<CharReader>;
5656
#else
57-
typedef std::auto_ptr<CharReader> CharReaderPtr;
57+
using CharReaderPtr = std::auto_ptr<CharReader>;
5858
#endif
5959

6060
// Implementation of class Features

src/lib_json/json_tool.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ enum {
7171
};
7272

7373
// Defines a char buffer for use with uintToString().
74-
typedef char UIntToStringBuffer[uintToStringBufferSize];
74+
using UIntToStringBuffer = char[uintToStringBufferSize];
7575

7676
/** Converts an unsigned integer to string.
7777
* @param value Unsigned integer to convert to string

src/lib_json/json_value.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ static inline char* duplicateStringValue(const char* value, size_t length) {
117117
if (length >= static_cast<size_t>(Value::maxInt))
118118
length = Value::maxInt - 1;
119119

120-
char* newString = static_cast<char*>(malloc(length + 1));
120+
auto newString = static_cast<char*>(malloc(length + 1));
121121
if (newString == nullptr) {
122122
throwRuntimeError("in Json::Value::duplicateStringValue(): "
123123
"Failed to allocate string value buffer");
@@ -137,8 +137,8 @@ static inline char* duplicateAndPrefixStringValue(const char* value,
137137
sizeof(unsigned) - 1U,
138138
"in Json::Value::duplicateAndPrefixStringValue(): "
139139
"length too big for prefixing");
140-
unsigned actualLength = length + static_cast<unsigned>(sizeof(unsigned)) + 1U;
141-
char* newString = static_cast<char*>(malloc(actualLength));
140+
size_t actualLength = sizeof(length) + length + 1;
141+
auto newString = static_cast<char*>(malloc(actualLength));
142142
if (newString == nullptr) {
143143
throwRuntimeError("in Json::Value::duplicateAndPrefixStringValue(): "
144144
"Failed to allocate string value buffer");
@@ -518,9 +518,10 @@ bool Value::operator<(const Value& other) const {
518518
}
519519
case arrayValue:
520520
case objectValue: {
521-
int delta = int(value_.map_->size() - other.value_.map_->size());
522-
if (delta)
523-
return delta < 0;
521+
auto thisSize = value_.map_->size();
522+
auto otherSize = other.value_.map_->size();
523+
if (thisSize != otherSize)
524+
return thisSize < otherSize;
524525
return (*value_.map_) < (*other.value_.map_);
525526
}
526527
default:

src/lib_json/json_writer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ namespace Json {
8686
#if __cplusplus >= 201103L || (defined(_CPPLIB_VER) && _CPPLIB_VER >= 520)
8787
using StreamWriterPtr = std::unique_ptr<StreamWriter>;
8888
#else
89-
typedef std::auto_ptr<StreamWriter> StreamWriterPtr;
89+
using StreamWriterPtr = std::auto_ptr<StreamWriter>;
9090
#endif
9191

9292
String valueToString(LargestInt value) {

src/test_lib_json/fuzz.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
4545
std::unique_ptr<Json::CharReader> reader(builder.newCharReader());
4646

4747
Json::Value root;
48-
const char* data_str = reinterpret_cast<const char*>(data);
48+
const auto data_str = reinterpret_cast<const char*>(data);
4949
try {
5050
reader->parse(data_str, data_str + size, &root, nullptr);
5151
} catch (Json::Exception const&) {

src/test_lib_json/jsontest.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class Failure {
4242
/// Must be a POD to allow inline initialisation without stepping
4343
/// into the debugger.
4444
struct PredicateContext {
45-
typedef unsigned int Id;
45+
using Id = unsigned int;
4646
Id id_;
4747
const char* file_;
4848
unsigned int line_;
@@ -102,7 +102,7 @@ class TestResult {
102102
static Json::String indentText(const Json::String& text,
103103
const Json::String& indent);
104104

105-
typedef std::deque<Failure> Failures;
105+
using Failures = std::deque<Failure>;
106106
Failures failures_;
107107
Json::String name_;
108108
PredicateContext rootPredicateNode_;
@@ -129,7 +129,7 @@ class TestCase {
129129
};
130130

131131
/// Function pointer type for TestCase factory
132-
typedef TestCase* (*TestCaseFactory)();
132+
using TestCaseFactory = TestCase* (*)();
133133

134134
class Runner {
135135
public:
@@ -168,7 +168,7 @@ class Runner {
168168
static void preventDialogOnCrash();
169169

170170
private:
171-
typedef std::deque<TestCaseFactory> Factories;
171+
using Factories = std::deque<TestCaseFactory>;
172172
Factories tests_;
173173
};
174174

0 commit comments

Comments
 (0)