Skip to content

Commit c273ddc

Browse files
committed
Style: Partially apply clang-tidy's cppcoreguidelines-pro-type-member-init
Didn't commit all the changes where it wants to initialize a struct with `{}`. Should be reviewed in a separate PR. Option `IgnoreArrays` enabled for now to be conservative, can be disabled to see if it proposes more useful changes. Also fixed manually a handful of other missing initializations / moved some from constructors.
1 parent dd06cb9 commit c273ddc

File tree

156 files changed

+757
-959
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

156 files changed

+757
-959
lines changed

.clang-tidy

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
Checks: 'clang-diagnostic-*,clang-analyzer-*,-*,modernize-redundant-void-arg,modernize-use-bool-literals,modernize-use-default-member-init,modernize-use-nullptr,readability-braces-around-statements,readability-redundant-member-init'
2+
Checks: 'clang-diagnostic-*,clang-analyzer-*,-*,cppcoreguidelines-pro-type-member-init,modernize-redundant-void-arg,modernize-use-bool-literals,modernize-use-default-member-init,modernize-use-nullptr,readability-braces-around-statements,readability-redundant-member-init'
33
WarningsAsErrors: ''
44
HeaderFilterRegex: ''
55
AnalyzeTemporaryDtors: false
@@ -13,6 +13,10 @@ CheckOptions:
1313
value: '1'
1414
- key: cppcoreguidelines-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic
1515
value: '1'
16+
- key: cppcoreguidelines-pro-type-member-init.IgnoreArrays
17+
value: '1'
18+
- key: cppcoreguidelines-pro-type-member-init.UseAssignment
19+
value: '1'
1620
- key: google-readability-function-size.StatementThreshold
1721
value: '800'
1822
- key: google-readability-namespace-comments.ShortNamespaceLines

core/config/project_settings.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -321,9 +321,9 @@ bool ProjectSettings::_get(const StringName &p_name, Variant &r_ret) const {
321321

322322
struct _VCSort {
323323
String name;
324-
Variant::Type type;
325-
int order;
326-
uint32_t flags;
324+
Variant::Type type = Variant::VARIANT_MAX;
325+
int order = 0;
326+
uint32_t flags = 0;
327327

328328
bool operator<(const _VCSort &p_vcs) const { return order == p_vcs.order ? name < p_vcs.name : order < p_vcs.order; }
329329
};

core/core_constants.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ struct _CoreConstant {
4141
StringName enum_name;
4242
bool ignore_value_in_docs = false;
4343
#endif
44-
const char *name;
44+
const char *name = nullptr;
4545
int value = 0;
4646

4747
_CoreConstant() {}

core/input/input.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,10 @@ class Input : public Object {
113113
int mouse_from_touch_index = -1;
114114

115115
struct VelocityTrack {
116-
uint64_t last_tick;
116+
uint64_t last_tick = 0;
117117
Vector2 velocity;
118118
Vector2 accum;
119-
float accum_t;
119+
float accum_t = 0.0f;
120120
float min_ref_frame;
121121
float max_ref_frame;
122122

core/io/file_access_network.h

+6-5
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,15 @@ class FileAccessNetwork : public FileAccess {
8686
Semaphore page_sem;
8787
Mutex buffer_mutex;
8888
bool opened = false;
89-
uint64_t total_size;
89+
uint64_t total_size = 0;
9090
mutable uint64_t pos = 0;
91-
int32_t id;
91+
int32_t id = -1;
9292
mutable bool eof_flag = false;
9393
mutable int32_t last_page = -1;
9494
mutable uint8_t *last_page_buff = nullptr;
9595

96-
int32_t page_size;
97-
int32_t read_ahead;
96+
int32_t page_size = 0;
97+
int32_t read_ahead = 0;
9898

9999
mutable int waiting_on_page = -1;
100100

@@ -108,7 +108,8 @@ class FileAccessNetwork : public FileAccess {
108108

109109
mutable Error response;
110110

111-
uint64_t exists_modtime;
111+
uint64_t exists_modtime = 0;
112+
112113
friend class FileAccessNetworkClient;
113114
void _queue_page(int32_t p_page) const;
114115
void _respond(uint64_t p_len, Error p_status);

core/io/file_access_zip.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class FileAccessZip : public FileAccess {
8080
unzFile zfile = nullptr;
8181
unz_file_info64 file_info;
8282

83-
mutable bool at_eof;
83+
mutable bool at_eof = false;
8484

8585
void _close();
8686

core/io/ip.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,7 @@ struct _IP_ResolverPrivate {
7474
Semaphore sem;
7575

7676
Thread thread;
77-
//Semaphore* semaphore;
78-
bool thread_abort;
77+
bool thread_abort = false;
7978

8079
void resolve_queues() {
8180
for (int i = 0; i < IP::RESOLVER_MAX_QUERIES; i++) {

core/math/convex_hull.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,7 @@ class ConvexHullInternal {
666666
face_pool.reset(true);
667667
}
668668

669-
Vertex *vertex_list;
669+
Vertex *vertex_list = nullptr;
670670

671671
void compute(const Vector3 *p_coords, int32_t p_count);
672672

core/math/geometry_2d.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,14 @@ Vector<Vector<Vector2>> Geometry2D::decompose_polygon_in_convex(Vector<Point2> p
7474
struct _AtlasWorkRect {
7575
Size2i s;
7676
Point2i p;
77-
int idx;
77+
int idx = 0;
7878
_FORCE_INLINE_ bool operator<(const _AtlasWorkRect &p_r) const { return s.width > p_r.s.width; };
7979
};
8080

8181
struct _AtlasWorkRectResult {
8282
Vector<_AtlasWorkRect> result;
83-
int max_w;
84-
int max_h;
83+
int max_w = 0;
84+
int max_h = 0;
8585
};
8686

8787
void Geometry2D::make_atlas(const Vector<Size2i> &p_rects, Vector<Point2i> &r_result, Size2i &r_size) {

core/math/random_pcg.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ static int __bsr_clz32(uint32_t x) {
6161

6262
class RandomPCG {
6363
pcg32_random_t pcg;
64-
uint64_t current_seed; // The seed the current generator state started from.
65-
uint64_t current_inc;
64+
uint64_t current_seed = 0; // The seed the current generator state started from.
65+
uint64_t current_inc = 0;
6666

6767
public:
6868
static const uint64_t DEFAULT_SEED = 12047754176567800795U;

core/os/os.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ class OS {
5454
bool _single_window = false;
5555
String _local_clipboard;
5656
int _exit_code = EXIT_FAILURE; // unexpected exit is marked as failure
57-
int _orientation;
5857
bool _allow_hidpi = false;
5958
bool _allow_layered = false;
6059
bool _stdout_enabled = true;
@@ -68,7 +67,7 @@ class OS {
6867
// for the user interface we keep a record of the current display driver
6968
// so we can retrieve the rendering drivers available
7069
int _display_driver_id = -1;
71-
String _current_rendering_driver_name = "";
70+
String _current_rendering_driver_name;
7271

7372
protected:
7473
void _set_logger(CompositeLogger *p_logger);

core/os/pool_allocator.h

+8-8
Original file line numberDiff line numberDiff line change
@@ -77,20 +77,20 @@ class PoolAllocator {
7777

7878
Entry *entry_array = nullptr;
7979
int *entry_indices = nullptr;
80-
int entry_max;
81-
int entry_count;
80+
int entry_max = 0;
81+
int entry_count = 0;
8282

8383
uint8_t *pool = nullptr;
8484
void *mem_ptr = nullptr;
85-
int pool_size;
85+
int pool_size = 0;
8686

87-
int free_mem;
88-
int free_mem_peak;
87+
int free_mem = 0;
88+
int free_mem_peak = 0;
8989

90-
unsigned int check_count;
91-
int align;
90+
unsigned int check_count = 0;
91+
int align = 1;
9292

93-
bool needs_locking;
93+
bool needs_locking = false;
9494

9595
inline int entry_end(const Entry &p_entry) const {
9696
return p_entry.pos + aligned(p_entry.len);

core/string/optimized_translation.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ extern "C" {
3737
}
3838

3939
struct CompressedString {
40-
int orig_len;
40+
int orig_len = 0;
4141
CharString compressed;
42-
int offset;
42+
int offset = 0;
4343
};
4444

4545
void OptimizedTranslation::generate(const Ref<Translation> &p_from) {

core/variant/variant_call.cpp

+9-9
Original file line numberDiff line numberDiff line change
@@ -949,20 +949,20 @@ struct _VariantCall {
949949
_VariantCall::ConstantData *_VariantCall::constant_data = nullptr;
950950

951951
struct VariantBuiltInMethodInfo {
952-
void (*call)(Variant *base, const Variant **p_args, int p_argcount, Variant &r_ret, const Vector<Variant> &p_defvals, Callable::CallError &r_error);
953-
Variant::ValidatedBuiltInMethod validated_call;
954-
Variant::PTRBuiltInMethod ptrcall;
952+
void (*call)(Variant *base, const Variant **p_args, int p_argcount, Variant &r_ret, const Vector<Variant> &p_defvals, Callable::CallError &r_error) = nullptr;
953+
Variant::ValidatedBuiltInMethod validated_call = nullptr;
954+
Variant::PTRBuiltInMethod ptrcall = nullptr;
955955

956956
Vector<Variant> default_arguments;
957957
Vector<String> argument_names;
958958

959-
bool is_const;
960-
bool is_static;
961-
bool has_return_type;
962-
bool is_vararg;
959+
bool is_const = false;
960+
bool is_static = false;
961+
bool has_return_type = false;
962+
bool is_vararg = false;
963963
Variant::Type return_type;
964-
int argument_count;
965-
Variant::Type (*get_argument_type)(int p_arg);
964+
int argument_count = 0;
965+
Variant::Type (*get_argument_type)(int p_arg) = nullptr;
966966
};
967967

968968
typedef OAHashMap<StringName, VariantBuiltInMethodInfo> BuiltinMethodMap;

core/variant/variant_construct.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@
3131
#include "variant_construct.h"
3232

3333
struct VariantConstructData {
34-
void (*construct)(Variant &r_base, const Variant **p_args, Callable::CallError &r_error);
35-
Variant::ValidatedConstructor validated_construct;
36-
Variant::PTRConstructor ptr_construct;
37-
Variant::Type (*get_argument_type)(int);
38-
int argument_count;
34+
void (*construct)(Variant &r_base, const Variant **p_args, Callable::CallError &r_error) = nullptr;
35+
Variant::ValidatedConstructor validated_construct = nullptr;
36+
Variant::PTRConstructor ptr_construct = nullptr;
37+
Variant::Type (*get_argument_type)(int) = nullptr;
38+
int argument_count = 0;
3939
Vector<String> arg_names;
4040
};
4141

core/variant/variant_setget.cpp

+13-13
Original file line numberDiff line numberDiff line change
@@ -805,16 +805,16 @@ INDEXED_SETGET_STRUCT_TYPED(PackedColorArray, Color)
805805
INDEXED_SETGET_STRUCT_DICT(Dictionary)
806806

807807
struct VariantIndexedSetterGetterInfo {
808-
void (*setter)(Variant *base, int64_t index, const Variant *value, bool *valid, bool *oob);
809-
void (*getter)(const Variant *base, int64_t index, Variant *value, bool *oob);
808+
void (*setter)(Variant *base, int64_t index, const Variant *value, bool *valid, bool *oob) = nullptr;
809+
void (*getter)(const Variant *base, int64_t index, Variant *value, bool *oob) = nullptr;
810810

811-
Variant::ValidatedIndexedSetter validated_setter;
812-
Variant::ValidatedIndexedGetter validated_getter;
811+
Variant::ValidatedIndexedSetter validated_setter = nullptr;
812+
Variant::ValidatedIndexedGetter validated_getter = nullptr;
813813

814-
Variant::PTRIndexedSetter ptr_setter;
815-
Variant::PTRIndexedGetter ptr_getter;
814+
Variant::PTRIndexedSetter ptr_setter = nullptr;
815+
Variant::PTRIndexedGetter ptr_getter = nullptr;
816816

817-
uint64_t (*get_indexed_size)(const Variant *base);
817+
uint64_t (*get_indexed_size)(const Variant *base) = nullptr;
818818

819819
Variant::Type index_type;
820820

@@ -1018,13 +1018,13 @@ struct VariantKeyedSetGetObject {
10181018
};
10191019

10201020
struct VariantKeyedSetterGetterInfo {
1021-
Variant::ValidatedKeyedSetter validated_setter;
1022-
Variant::ValidatedKeyedGetter validated_getter;
1023-
Variant::ValidatedKeyedChecker validated_checker;
1021+
Variant::ValidatedKeyedSetter validated_setter = nullptr;
1022+
Variant::ValidatedKeyedGetter validated_getter = nullptr;
1023+
Variant::ValidatedKeyedChecker validated_checker = nullptr;
10241024

1025-
Variant::PTRKeyedSetter ptr_setter;
1026-
Variant::PTRKeyedGetter ptr_getter;
1027-
Variant::PTRKeyedChecker ptr_checker;
1025+
Variant::PTRKeyedSetter ptr_setter = nullptr;
1026+
Variant::PTRKeyedGetter ptr_getter = nullptr;
1027+
Variant::PTRKeyedChecker ptr_checker = nullptr;
10281028

10291029
bool valid = false;
10301030
};

core/variant/variant_utility.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -1110,14 +1110,14 @@ static _FORCE_INLINE_ Variant::Type get_ret_type_helper(void (*p_func)(P...)) {
11101110
register_utility_function<Func_##m_func>(#m_func, m_args)
11111111

11121112
struct VariantUtilityFunctionInfo {
1113-
void (*call_utility)(Variant *r_ret, const Variant **p_args, int p_argcount, Callable::CallError &r_error);
1114-
Variant::ValidatedUtilityFunction validated_call_utility;
1115-
Variant::PTRUtilityFunction ptr_call_utility;
1113+
void (*call_utility)(Variant *r_ret, const Variant **p_args, int p_argcount, Callable::CallError &r_error) = nullptr;
1114+
Variant::ValidatedUtilityFunction validated_call_utility = nullptr;
1115+
Variant::PTRUtilityFunction ptr_call_utility = nullptr;
11161116
Vector<String> argnames;
1117-
bool is_vararg;
1118-
bool returns_value;
1119-
int argcount;
1120-
Variant::Type (*get_arg_type)(int);
1117+
bool is_vararg = false;
1118+
bool returns_value = false;
1119+
int argcount = 0;
1120+
Variant::Type (*get_arg_type)(int) = nullptr;
11211121
Variant::Type return_type;
11221122
Variant::UtilityFunctionType type;
11231123
};

drivers/gles3/rasterizer_storage_gles3.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class RasterizerStorageGLES3 : public RendererStorage {
5353
// RasterizerCanvasGLES3 *canvas;
5454
// RasterizerSceneGLES3 *scene;
5555

56-
GLES3::Config *config;
56+
GLES3::Config *config = nullptr;
5757

5858
struct Resources {
5959
GLuint mipmap_blur_fbo;

drivers/gles3/shader_gles3.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ class ShaderGLES3 {
141141
static bool shader_cache_save_debug;
142142
bool shader_cache_dir_valid = false;
143143

144-
GLint max_image_units;
144+
GLint max_image_units = 0;
145145

146146
enum StageType {
147147
STAGE_TYPE_VERTEX,

0 commit comments

Comments
 (0)