Skip to content

Commit d452d19

Browse files
committed
PVS and clang-tidy modify
1 parent c634b98 commit d452d19

File tree

14 files changed

+60
-60
lines changed

14 files changed

+60
-60
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
@@ -135,23 +135,23 @@ extern JSON_API int msvc_pre1900_c99_snprintf(char* outBuf, size_t size,
135135
#endif // if !defined(JSON_IS_AMALGAMATION)
136136

137137
namespace Json {
138-
typedef int Int;
139-
typedef unsigned int UInt;
138+
using Int = int;
139+
using UInt = unsigned int;
140140
#if defined(JSON_NO_INT64)
141-
typedef int LargestInt;
142-
typedef unsigned int LargestUInt;
141+
using LargestInt = int;
142+
using LargestUInt = unsigned int;
143143
#undef JSON_HAS_INT64
144144
#else // if defined(JSON_NO_INT64)
145145
// For Microsoft Visual use specific types as long long is not supported
146146
#if defined(_MSC_VER) // Microsoft Visual Studio
147-
typedef __int64 Int64;
148-
typedef unsigned __int64 UInt64;
147+
using Int64 = __int64;
148+
using UInt64 = unsigned __int64;
149149
#else // if defined(_MSC_VER) // Other platforms, use long long
150-
typedef int64_t Int64;
151-
typedef uint64_t UInt64;
150+
using Int64 = int64_t;
151+
using UInt64 = uint64_t;
152152
#endif // if defined(_MSC_VER)
153-
typedef Int64 LargestInt;
154-
typedef UInt64 LargestUInt;
153+
using LargestInt = Int64;
154+
using LargestUInt = UInt64;
155155
#define JSON_HAS_INT64
156156
#endif // if defined(JSON_NO_INT64)
157157

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: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -189,21 +189,21 @@ class JSON_API Value {
189189
friend class ValueIteratorBase;
190190

191191
public:
192-
typedef std::vector<String> Members;
193-
typedef ValueIterator iterator;
194-
typedef ValueConstIterator const_iterator;
195-
typedef Json::UInt UInt;
196-
typedef Json::Int Int;
192+
using Members = std::vector<String>;
193+
using iterator = ValueIterator;
194+
using const_iterator = ValueConstIterator;
195+
using UInt = Json::UInt;
196+
using Int = Json::Int;
197197
#if defined(JSON_HAS_INT64)
198-
typedef Json::UInt64 UInt64;
199-
typedef Json::Int64 Int64;
198+
using UInt64 = Json::UInt64;
199+
using Int64 = Json::Int64;
200200
#endif // defined(JSON_HAS_INT64)
201-
typedef Json::LargestInt LargestInt;
202-
typedef Json::LargestUInt LargestUInt;
203-
typedef Json::ArrayIndex ArrayIndex;
201+
using LargestInt = Json::LargestInt;
202+
using LargestUInt = Json::LargestUInt;
203+
using ArrayIndex = Json::ArrayIndex;
204204

205205
// Required for boost integration, e. g. BOOST_TEST
206-
typedef std::string value_type;
206+
using value_type = std::string;
207207

208208
#if JSON_USE_NULLREF
209209
// Binary compatibility kludges, do not use.
@@ -288,9 +288,9 @@ class JSON_API Value {
288288

289289
public:
290290
#ifndef JSON_USE_CPPTL_SMALLMAP
291-
typedef std::map<CZString, Value> ObjectValues;
291+
using ObjectValues = std::map<CZString, Value>;
292292
#else
293-
typedef CppTL::SmallMap<CZString, Value> ObjectValues;
293+
using ObjectValues = CppTL::SmallMap<CZString, Value>;
294294
#endif // ifndef JSON_USE_CPPTL_SMALLMAP
295295
#endif // ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION
296296

@@ -718,8 +718,8 @@ class JSON_API Path {
718718
Value& make(Value& root) const;
719719

720720
private:
721-
typedef std::vector<const PathArgument*> InArgs;
722-
typedef std::vector<PathArgument> Args;
721+
using InArgs = std::vector<const PathArgument*>;
722+
using Args = std::vector<PathArgument>;
723723

724724
void makePath(const String& path, const InArgs& in);
725725
void addPathInArg(const String& path, const InArgs& in,
@@ -734,10 +734,10 @@ class JSON_API Path {
734734
*/
735735
class JSON_API ValueIteratorBase {
736736
public:
737-
typedef std::bidirectional_iterator_tag iterator_category;
738-
typedef unsigned int size_t;
739-
typedef int difference_type;
740-
typedef ValueIteratorBase SelfType;
737+
using iterator_category = std::bidirectional_iterator_tag;
738+
using size_t = unsigned int;
739+
using difference_type = int;
740+
using SelfType = ValueIteratorBase;
741741

742742
bool operator==(const SelfType& other) const { return isEqual(other); }
743743

@@ -810,12 +810,12 @@ class JSON_API ValueConstIterator : public ValueIteratorBase {
810810
friend class Value;
811811

812812
public:
813-
typedef const Value value_type;
813+
using value_type = const Value;
814814
// typedef unsigned int size_t;
815815
// typedef int difference_type;
816-
typedef const Value& reference;
817-
typedef const Value* pointer;
818-
typedef ValueConstIterator SelfType;
816+
using reference = const Value&;
817+
using pointer = const Value*;
818+
using SelfType = ValueConstIterator;
819819

820820
ValueConstIterator();
821821
ValueConstIterator(ValueIterator const& other);
@@ -861,12 +861,12 @@ class JSON_API ValueIterator : public ValueIteratorBase {
861861
friend class Value;
862862

863863
public:
864-
typedef Value value_type;
865-
typedef unsigned int size_t;
866-
typedef int difference_type;
867-
typedef Value& reference;
868-
typedef Value* pointer;
869-
typedef ValueIterator SelfType;
864+
using value_type = Value;
865+
using size_t = unsigned int;
866+
using difference_type = int;
867+
using reference = Value&;
868+
using pointer = Value*;
869+
using SelfType = ValueIterator;
870870

871871
ValueIterator();
872872
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
@@ -56,7 +56,7 @@ static Json::String readInputTestFile(const char* path) {
5656
return "";
5757
fseek(file, 0, SEEK_END);
5858
long const size = ftell(file);
59-
size_t const usize = static_cast<unsigned long>(size);
59+
auto const usize = static_cast<unsigned long>(size);
6060
fseek(file, 0, SEEK_SET);
6161
char* buffer = new char[size + 1];
6262
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: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ static inline char* duplicateStringValue(const char* value, size_t length) {
120120
if (length >= static_cast<size_t>(Value::maxInt))
121121
length = Value::maxInt - 1;
122122

123-
char* newString = static_cast<char*>(malloc(length + 1));
123+
auto newString = static_cast<char*>(malloc(length + 1));
124124
if (newString == nullptr) {
125125
throwRuntimeError("in Json::Value::duplicateStringValue(): "
126126
"Failed to allocate string value buffer");
@@ -141,7 +141,7 @@ static inline char* duplicateAndPrefixStringValue(const char* value,
141141
"in Json::Value::duplicateAndPrefixStringValue(): "
142142
"length too big for prefixing");
143143
unsigned actualLength = length + static_cast<unsigned>(sizeof(unsigned)) + 1U;
144-
char* newString = static_cast<char*>(malloc(actualLength));
144+
auto newString = static_cast<char*>(malloc(actualLength));
145145
if (newString == nullptr) {
146146
throwRuntimeError("in Json::Value::duplicateAndPrefixStringValue(): "
147147
"Failed to allocate string value buffer");
@@ -529,7 +529,7 @@ bool Value::operator<(const Value& other) const {
529529
}
530530
case arrayValue:
531531
case objectValue: {
532-
int delta = int(value_.map_->size() - other.value_.map_->size());
532+
auto delta = int(value_.map_->size() - other.value_.map_->size());
533533
if (delta)
534534
return delta < 0;
535535
return (*value_.map_) < (*other.value_.map_);

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
@@ -44,7 +44,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
4444
std::unique_ptr<Json::CharReader> reader(builder.newCharReader());
4545

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

src/test_lib_json/jsontest.h

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

106-
typedef std::deque<Failure> Failures;
106+
using Failures = std::deque<Failure>;
107107
Failures failures_;
108108
Json::String name_;
109109
PredicateContext rootPredicateNode_;
@@ -130,7 +130,7 @@ class TestCase {
130130
};
131131

132132
/// Function pointer type for TestCase factory
133-
typedef TestCase* (*TestCaseFactory)();
133+
using TestCaseFactory = TestCase* (*)();
134134

135135
class Runner {
136136
public:
@@ -169,7 +169,7 @@ class Runner {
169169
static void preventDialogOnCrash();
170170

171171
private:
172-
typedef std::deque<TestCaseFactory> Factories;
172+
using Factories = std::deque<TestCaseFactory>;
173173
Factories tests_;
174174
};
175175

0 commit comments

Comments
 (0)