Skip to content

Commit

Permalink
Merge pull request #93401 from Repiteo/style/clang-tidy-fixes
Browse files Browse the repository at this point in the history
Style: Apply `clang-tidy` fixes
  • Loading branch information
Repiteo committed Nov 5, 2024
2 parents 7d950c1 + 2dcfdde commit 2450dee
Show file tree
Hide file tree
Showing 67 changed files with 166 additions and 149 deletions.
21 changes: 9 additions & 12 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
---
Checks: >-
-*,
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
WarningsAsErrors: ''
Checks:
- -*
- 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
HeaderFileExtensions: ['', h, hh, hpp, hxx, inc, glsl]
ImplementationFileExtensions: [c, cc, cpp, cxx, m, mm, java]
HeaderFilterRegex: (core|doc|drivers|editor|main|modules|platform|scene|servers|tests)/
Expand All @@ -19,4 +17,3 @@ CheckOptions:
modernize-use-bool-literals.IgnoreMacros: false
modernize-use-default-member-init.IgnoreMacros: false
modernize-use-default-member-init.UseAssignment: true
...
3 changes: 3 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,6 @@ b37fc1014abf7adda70dc30b0822d775b3a4433f

# Set clang-format `RemoveSemicolon` rule to `true`
0d350e71086fffce0553811739aae9f6ad66136c

# Style: Apply clang-tidy fixes (superficial)
bb5f390fb9b466be35a5df7651323d7e66afca31
2 changes: 1 addition & 1 deletion core/input/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1034,7 +1034,7 @@ void Input::action_release(const StringName &p_action) {

// Create or retrieve existing action.
ActionState &action_state = action_states[p_action];
action_state.cache.pressed = 0;
action_state.cache.pressed = false;
action_state.cache.strength = 0.0;
action_state.cache.raw_strength = 0.0;
// As input may come in part way through a physics tick, the earliest we can react to it is the next physics tick.
Expand Down
2 changes: 1 addition & 1 deletion core/object/message_queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ class CallQueue {
bool is_flushing() const;
int get_max_buffer_usage() const;

CallQueue(Allocator *p_custom_allocator = 0, uint32_t p_max_pages = 8192, const String &p_error_text = String());
CallQueue(Allocator *p_custom_allocator = nullptr, uint32_t p_max_pages = 8192, const String &p_error_text = String());
virtual ~CallQueue();
};

Expand Down
2 changes: 0 additions & 2 deletions core/typedefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,4 @@ struct BuildIndexSequence<0, Is...> : IndexSequence<Is...> {};
#define ___gd_is_defined(val) ____gd_is_defined(__GDARG_PLACEHOLDER_##val)
#define GD_IS_DEFINED(x) ___gd_is_defined(x)

#define FORCE_SEMICOLON ;

#endif // TYPEDEFS_H
12 changes: 4 additions & 8 deletions core/variant/variant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2719,8 +2719,7 @@ Variant::Variant(const Vector<Plane> &p_array) :
}
}

Variant::Variant(const Vector<Face3> &p_face_array) :
type(NIL) {
Variant::Variant(const Vector<Face3> &p_face_array) {
PackedVector3Array vertices;
int face_count = p_face_array.size();
vertices.resize(face_count * 3);
Expand All @@ -2739,8 +2738,7 @@ Variant::Variant(const Vector<Face3> &p_face_array) :
*this = vertices;
}

Variant::Variant(const Vector<Variant> &p_array) :
type(NIL) {
Variant::Variant(const Vector<Variant> &p_array) {
Array arr;
arr.resize(p_array.size());
for (int i = 0; i < p_array.size(); i++) {
Expand All @@ -2749,8 +2747,7 @@ Variant::Variant(const Vector<Variant> &p_array) :
*this = arr;
}

Variant::Variant(const Vector<StringName> &p_array) :
type(NIL) {
Variant::Variant(const Vector<StringName> &p_array) {
PackedStringArray v;
int len = p_array.size();
v.resize(len);
Expand Down Expand Up @@ -2908,8 +2905,7 @@ Variant::Variant(const IPAddress &p_address) :
memnew_placement(_data._mem, String(p_address));
}

Variant::Variant(const Variant &p_variant) :
type(NIL) {
Variant::Variant(const Variant &p_variant) {
reference(p_variant);
}

Expand Down
3 changes: 1 addition & 2 deletions core/variant/variant.h
Original file line number Diff line number Diff line change
Expand Up @@ -814,8 +814,7 @@ class Variant {
static void unregister_types();

Variant(const Variant &p_variant);
_FORCE_INLINE_ Variant() :
type(NIL) {}
_FORCE_INLINE_ Variant() {}
_FORCE_INLINE_ ~Variant() {
clear();
}
Expand Down
2 changes: 1 addition & 1 deletion drivers/gles3/storage/particles_storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ class ParticlesStorage : public RendererParticlesStorage {

_FORCE_INLINE_ bool particles_has_collision(RID p_particles) {
Particles *particles = particles_owner.get_or_null(p_particles);
ERR_FAIL_NULL_V(particles, 0);
ERR_FAIL_NULL_V(particles, false);

return particles->has_collision_cache;
}
Expand Down
6 changes: 3 additions & 3 deletions drivers/vulkan/rendering_device_driver_vulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1519,7 +1519,7 @@ RDD::BufferID RenderingDeviceDriverVulkan::buffer_create(uint64_t p_size, BitFie
ERR_FAIL_COND_V_MSG(err, BufferID(), "Can't create buffer of size: " + itos(p_size) + ", error " + itos(err) + ".");
err = vmaAllocateMemoryForBuffer(allocator, vk_buffer, &alloc_create_info, &allocation, &alloc_info);
ERR_FAIL_COND_V_MSG(err, BufferID(), "Can't allocate memory for buffer of size: " + itos(p_size) + ", error " + itos(err) + ".");
err = vmaBindBufferMemory2(allocator, allocation, 0, vk_buffer, NULL);
err = vmaBindBufferMemory2(allocator, allocation, 0, vk_buffer, nullptr);
ERR_FAIL_COND_V_MSG(err, BufferID(), "Can't bind memory to buffer of size: " + itos(p_size) + ", error " + itos(err) + ".");

// Bookkeep.
Expand Down Expand Up @@ -1745,7 +1745,7 @@ RDD::TextureID RenderingDeviceDriverVulkan::texture_create(const TextureFormat &
ERR_FAIL_COND_V_MSG(err, TextureID(), "vkCreateImage failed with error " + itos(err) + ".");
err = vmaAllocateMemoryForImage(allocator, vk_image, &alloc_create_info, &allocation, &alloc_info);
ERR_FAIL_COND_V_MSG(err, TextureID(), "Can't allocate memory for image, error: " + itos(err) + ".");
err = vmaBindImageMemory2(allocator, allocation, 0, vk_image, NULL);
err = vmaBindImageMemory2(allocator, allocation, 0, vk_image, nullptr);
ERR_FAIL_COND_V_MSG(err, TextureID(), "Can't bind memory to image, error: " + itos(err) + ".");

// Create view.
Expand Down Expand Up @@ -4042,7 +4042,7 @@ RDD::UniformSetID RenderingDeviceDriverVulkan::uniform_set_create(VectorView<Bou
}

// Need a descriptor pool.
DescriptorSetPools::Iterator pool_sets_it = {};
DescriptorSetPools::Iterator pool_sets_it;
VkDescriptorPool vk_pool = _descriptor_set_pool_find_or_create(pool_key, &pool_sets_it);
DEV_ASSERT(vk_pool);
pool_sets_it->value[vk_pool]++;
Expand Down
2 changes: 1 addition & 1 deletion drivers/vulkan/rendering_device_driver_vulkan.h
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ class RenderingDeviceDriverVulkan : public RenderingDeviceDriver {
struct UniformSetInfo {
VkDescriptorSet vk_descriptor_set = VK_NULL_HANDLE;
VkDescriptorPool vk_descriptor_pool = VK_NULL_HANDLE;
DescriptorSetPools::Iterator pool_sets_it = {};
DescriptorSetPools::Iterator pool_sets_it;
};

public:
Expand Down
2 changes: 1 addition & 1 deletion drivers/windows/dir_access_windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ Error DirAccessWindows::rename(String p_path, String p_new_path) {
uint64_t id = OS::get_singleton()->get_ticks_usec();
while (true) {
tmpfile_utf16 = (path + itos(id++) + ".tmp").utf16();
HANDLE handle = CreateFileW((LPCWSTR)tmpfile_utf16.get_data(), GENERIC_WRITE, 0, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, 0);
HANDLE handle = CreateFileW((LPCWSTR)tmpfile_utf16.get_data(), GENERIC_WRITE, 0, nullptr, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, nullptr);
if (handle != INVALID_HANDLE_VALUE) {
CloseHandle(handle);
break;
Expand Down
2 changes: 1 addition & 1 deletion drivers/windows/file_access_windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ Error FileAccessWindows::open_internal(const String &p_path, int p_mode_flags) {
uint64_t id = OS::get_singleton()->get_ticks_usec();
while (true) {
tmpfile = path + itos(id++) + ".tmp";
HANDLE handle = CreateFileW((LPCWSTR)tmpfile.utf16().get_data(), GENERIC_WRITE, 0, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, 0);
HANDLE handle = CreateFileW((LPCWSTR)tmpfile.utf16().get_data(), GENERIC_WRITE, 0, nullptr, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, nullptr);
if (handle != INVALID_HANDLE_VALUE) {
CloseHandle(handle);
break;
Expand Down
20 changes: 10 additions & 10 deletions drivers/windows/file_access_windows_pipe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Error FileAccessWindowsPipe::open_existing(HANDLE p_rfd, HANDLE p_wfd, bool p_bl
_close();

path_src = String();
ERR_FAIL_COND_V_MSG(fd[0] != 0 || fd[1] != 0, ERR_ALREADY_IN_USE, "Pipe is already in use.");
ERR_FAIL_COND_V_MSG(fd[0] != nullptr || fd[1] != nullptr, ERR_ALREADY_IN_USE, "Pipe is already in use.");
fd[0] = p_rfd;
fd[1] = p_wfd;

Expand All @@ -58,18 +58,18 @@ Error FileAccessWindowsPipe::open_internal(const String &p_path, int p_mode_flag
_close();

path_src = p_path;
ERR_FAIL_COND_V_MSG(fd[0] != 0 || fd[1] != 0, ERR_ALREADY_IN_USE, "Pipe is already in use.");
ERR_FAIL_COND_V_MSG(fd[0] != nullptr || fd[1] != nullptr, ERR_ALREADY_IN_USE, "Pipe is already in use.");

path = String("\\\\.\\pipe\\LOCAL\\") + p_path.replace("pipe://", "").replace("/", "_");

HANDLE h = CreateFileW((LPCWSTR)path.utf16().get_data(), GENERIC_READ | GENERIC_WRITE, 0, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
HANDLE h = CreateFileW((LPCWSTR)path.utf16().get_data(), GENERIC_READ | GENERIC_WRITE, 0, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr);
if (h == INVALID_HANDLE_VALUE) {
h = CreateNamedPipeW((LPCWSTR)path.utf16().get_data(), PIPE_ACCESS_DUPLEX, PIPE_TYPE_BYTE | PIPE_READMODE_BYTE | PIPE_NOWAIT, 1, 4096, 4096, 0, nullptr);
if (h == INVALID_HANDLE_VALUE) {
last_error = ERR_FILE_CANT_OPEN;
return last_error;
}
ConnectNamedPipe(h, NULL);
ConnectNamedPipe(h, nullptr);
}
fd[0] = h;
fd[1] = h;
Expand All @@ -79,19 +79,19 @@ Error FileAccessWindowsPipe::open_internal(const String &p_path, int p_mode_flag
}

void FileAccessWindowsPipe::_close() {
if (fd[0] == 0) {
if (fd[0] == nullptr) {
return;
}
if (fd[1] != fd[0]) {
CloseHandle(fd[1]);
}
CloseHandle(fd[0]);
fd[0] = 0;
fd[1] = 0;
fd[0] = nullptr;
fd[1] = nullptr;
}

bool FileAccessWindowsPipe::is_open() const {
return (fd[0] != 0 || fd[1] != 0);
return (fd[0] != nullptr || fd[1] != nullptr);
}

String FileAccessWindowsPipe::get_path() const {
Expand All @@ -103,7 +103,7 @@ String FileAccessWindowsPipe::get_path_absolute() const {
}

uint64_t FileAccessWindowsPipe::get_buffer(uint8_t *p_dst, uint64_t p_length) const {
ERR_FAIL_COND_V_MSG(fd[0] == 0, -1, "Pipe must be opened before use.");
ERR_FAIL_COND_V_MSG(fd[0] == nullptr, -1, "Pipe must be opened before use.");
ERR_FAIL_COND_V(!p_dst && p_length > 0, -1);

DWORD read = 0;
Expand All @@ -120,7 +120,7 @@ Error FileAccessWindowsPipe::get_error() const {
}

void FileAccessWindowsPipe::store_buffer(const uint8_t *p_src, uint64_t p_length) {
ERR_FAIL_COND_MSG(fd[1] == 0, "Pipe must be opened before use.");
ERR_FAIL_COND_MSG(fd[1] == nullptr, "Pipe must be opened before use.");
ERR_FAIL_COND(!p_src && p_length > 0);

DWORD read = -1;
Expand Down
2 changes: 1 addition & 1 deletion drivers/windows/file_access_windows_pipe.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
class FileAccessWindowsPipe : public FileAccess {
HANDLE fd[2] = { 0, 0 };
HANDLE fd[2] = { nullptr, nullptr };

mutable Error last_error = OK;

Expand Down
3 changes: 2 additions & 1 deletion editor/animation_track_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6337,8 +6337,9 @@ bool AnimationTrackEditor::_is_track_compatible(int p_target_track_idx, Variant:
}

if (path_valid) {
if (is_source_bezier)
if (is_source_bezier) {
p_source_value_type = Variant::FLOAT;
}
return property_type == p_source_value_type;
} else {
if (animation->track_get_key_count(p_target_track_idx) > 0) {
Expand Down
2 changes: 1 addition & 1 deletion editor/editor_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,7 @@ class EditorNode : public Node {

struct AdditiveNodeEntry {
Node *node = nullptr;
NodePath parent = NodePath();
NodePath parent;
Node *owner = nullptr;
int index = 0;
// Used if the original parent node is lost
Expand Down
3 changes: 2 additions & 1 deletion editor/gui/editor_quick_open_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -649,8 +649,9 @@ QuickOpenDisplayMode QuickOpenResultContainer::get_adaptive_display_mode(const V

for (const StringName &type : grid_preferred_types) {
for (const StringName &base_type : p_base_types) {
if (base_type == type || ClassDB::is_parent_class(base_type, type))
if (base_type == type || ClassDB::is_parent_class(base_type, type)) {
return QuickOpenDisplayMode::GRID;
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions editor/plugins/bone_map_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,7 @@ void BoneMapper::auto_mapping_process(Ref<BoneMap> &p_bone_map) {

// 4-1. Guess Finger
int tips_index = -1;
bool thumb_tips_size = 0;
bool thumb_tips_size = false;
bool named_finger_is_found = false;
LocalVector<String> fingers;
fingers.push_back("thumb|pollex");
Expand Down Expand Up @@ -994,7 +994,7 @@ void BoneMapper::auto_mapping_process(Ref<BoneMap> &p_bone_map) {
}

tips_index = -1;
thumb_tips_size = 0;
thumb_tips_size = false;
named_finger_is_found = false;
if (right_hand_or_palm != -1) {
LocalVector<LocalVector<String>> right_fingers_map;
Expand Down
2 changes: 1 addition & 1 deletion editor/plugins/font_config_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ void EditorPropertyOTVariation::update_property() {
Vector3i range = supported.get_value_at_index(i);

EditorPropertyInteger *prop = memnew(EditorPropertyInteger);
prop->setup(range.x, range.y, false, 1, false, false);
prop->setup(range.x, range.y, false, true, false, false);
prop->set_object_and_property(object.ptr(), "keys/" + itos(name_tag));

String name = TS->tag_to_name(name_tag);
Expand Down
2 changes: 2 additions & 0 deletions editor/plugins/tiles/tile_map_layer_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1550,6 +1550,7 @@ int TileMapLayerEditorTilesPlugin::_get_transformed_alternative(int p_alternativ
case TRANSFORM_ROTATE_RIGHT: {
// A matrix with every possible flip/transpose combination, sorted by what comes next when you rotate.
const LocalVector<bool> rotation_matrix = {
// NOLINTBEGIN(modernize-use-bool-literals)
0, 0, 0,
0, 1, 1,
1, 1, 0,
Expand All @@ -1558,6 +1559,7 @@ int TileMapLayerEditorTilesPlugin::_get_transformed_alternative(int p_alternativ
0, 0, 1,
0, 1, 0,
1, 1, 1
// NOLINTEND(modernize-use-bool-literals)
};

for (int i = 0; i < 8; i++) {
Expand Down
2 changes: 1 addition & 1 deletion editor/plugins/tiles/tile_set_atlas_source_editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class TileSetAtlasSourceEditor : public HSplitContainer {
TileSetAtlasSourceEditor *tiles_set_atlas_source_editor = nullptr;

Ref<TileSetAtlasSource> tile_set_atlas_source;
RBSet<TileSelection> tiles = RBSet<TileSelection>();
RBSet<TileSelection> tiles;

protected:
bool _set(const StringName &p_name, const Variant &p_value);
Expand Down
6 changes: 4 additions & 2 deletions editor/project_converter_3_to_4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -716,8 +716,9 @@ Vector<String> ProjectConverter3To4::check_for_files() {
directories_to_check.append(current_dir.path_join(file_name) + "/");
} else {
bool proper_extension = false;
if (file_name.ends_with(".gd") || file_name.ends_with(".shader") || file_name.ends_with(".gdshader") || file_name.ends_with(".tscn") || file_name.ends_with(".tres") || file_name.ends_with(".godot") || file_name.ends_with(".cs") || file_name.ends_with(".csproj") || file_name.ends_with(".import"))
if (file_name.ends_with(".gd") || file_name.ends_with(".shader") || file_name.ends_with(".gdshader") || file_name.ends_with(".tscn") || file_name.ends_with(".tres") || file_name.ends_with(".godot") || file_name.ends_with(".cs") || file_name.ends_with(".csproj") || file_name.ends_with(".import")) {
proper_extension = true;
}

if (proper_extension) {
collected_files.append(current_dir.path_join(file_name));
Expand Down Expand Up @@ -1321,8 +1322,9 @@ Vector<String> ProjectConverter3To4::parse_arguments(const String &line) {
break;
};
case '"': {
if (previous_character != '\\')
if (previous_character != '\\') {
is_inside_string = !is_inside_string;
}
}
}
previous_character = character;
Expand Down
4 changes: 2 additions & 2 deletions modules/betsy/image_compress_betsy.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@ class BetsyCompressor : public Object {
RenderingDevice *compress_rd = nullptr;
RenderingContextDriver *compress_rcd = nullptr;
HashMap<String, BetsyShader> cached_shaders;
RID src_sampler = RID();
RID src_sampler;

// Format-specific resources.
RID dxt1_encoding_table_buffer = RID();
RID dxt1_encoding_table_buffer;

void _init();
void _assign_mt_ids(WorkerThreadPool::TaskID p_pump_task_id);
Expand Down
2 changes: 1 addition & 1 deletion modules/camera/camera_feed_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ bool CameraFeedLinux::_request_buffers() {
}

buffers[i].length = buffer.length;
buffers[i].start = mmap(NULL, buffer.length, PROT_READ | PROT_WRITE, MAP_SHARED, file_descriptor, buffer.m.offset);
buffers[i].start = mmap(nullptr, buffer.length, PROT_READ | PROT_WRITE, MAP_SHARED, file_descriptor, buffer.m.offset);

if (buffers[i].start == MAP_FAILED) {
for (unsigned int b = 0; b < i; b++) {
Expand Down
Loading

0 comments on commit 2450dee

Please sign in to comment.