Skip to content

Commit

Permalink
Fix warnings in Clang and disable warnings in external code
Browse files Browse the repository at this point in the history
  • Loading branch information
aeris170 committed Sep 2, 2024
1 parent dfebd5e commit 0c5f80a
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 12 deletions.
17 changes: 10 additions & 7 deletions Editor/CodeEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void CodeEditor::Render() {
ImGuiTabBarFlags tabBarFlags = ImGuiTabBarFlags_AutoSelectNewTabs |
ImGuiTabBarFlags_FittingPolicyResizeDown | ImGuiTabBarFlags_Reorderable;
if(ImGui::BeginTabBar("#CodeEditorOpenTabs", tabBarFlags)) {
for (auto i = 0; i < tabs.size(); i++) {
for (size_t i = 0; i < tabs.size(); i++) {
if (i == removedTabIndex) { continue; }

auto& tab = tabs[i];
Expand Down Expand Up @@ -66,14 +66,14 @@ void CodeEditor::End() {
ImGui::End();
ImGui::PopID();

if (removedTabIndex != -1) {
if (removedTabIndex != std::numeric_limits<decltype(removedTabIndex)>::max()) {
tabs.erase(tabs.begin() + removedTabIndex);
removedTabIndex = -1;
removedTabIndex = std::numeric_limits<decltype(removedTabIndex)>::max();
}
}

void CodeEditor::RenderMenuBar() {
bool menuBarEnabled = selectedTabIndex != -1;
bool menuBarEnabled = selectedTabIndex != std::numeric_limits<decltype(selectedTabIndex)>::max();
if (menuBarEnabled) {
bool shortcutsEnabled = menuBarEnabled;
if (ImGui::Shortcut(ImGuiMod_Ctrl | ImGuiKey_S) && shortcutsEnabled) {
Expand Down Expand Up @@ -185,10 +185,13 @@ void CodeEditor::AddTab(AssetHandle assetHandle) {
selectedTabIndex++;
}

void CodeEditor::CloseTabAt(int index) {
void CodeEditor::CloseTabAt(size_t index) {
removedTabIndex = index;
if (removedTabIndex <= selectedTabIndex) {
selectedTabIndex = std::max(0, selectedTabIndex--);
selectedTabIndex--;
if(selectedTabIndex == std::numeric_limits<decltype(selectedTabIndex)>::max()) {
selectedTabIndex = 0;
}
}
}

Expand All @@ -204,7 +207,7 @@ void CodeEditor::OnReimport(Assets& assets) {
}
}
void CodeEditor::OnAssetDeleted(AssetHandle handle) {
for (int i = 0; i < tabs.size(); i++) {
for (size_t i = 0; i < tabs.size(); i++) {
if (tabs[i].currentAsset == handle) {
CloseTabAt(i);
return;
Expand Down
6 changes: 3 additions & 3 deletions Editor/CodeEditor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ struct CodeEditor {
bool isWhitespaceVisible{ true };
int tabSize{ 4 };

int selectedTabIndex{ -1 };
size_t selectedTabIndex{ std::numeric_limits<size_t>::max() };
std::vector<EditorTab> tabs{};
EditorTab emptyTab{};

int removedTabIndex{ -1 };
size_t removedTabIndex{ std::numeric_limits<size_t>::max() };

void AddTab(AssetHandle assetHandle);
void CloseTabAt(int index);
void CloseTabAt(size_t index);

void RenderMenuBar();

Expand Down
10 changes: 10 additions & 0 deletions Editor/ImGuiDebugPanel.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
// This is external code. Disabling warnings.
#if defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wsign-compare"
#endif

#if _DEBUG

#include <Editor/TextEditor.hpp>
Expand Down Expand Up @@ -232,4 +238,8 @@ void TextEditor::UnitTests() {
assert(!FindNextOccurrence("lalal", 4, { 3, 5 }, outStart, outEnd)); // not found
}
}
#endif

#if defined(__clang__)
#pragma clang diagnostic pop
#endif
14 changes: 13 additions & 1 deletion Editor/TextEditor.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
// This is external code. Disabling warnings.
#if defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wreorder-ctor"
#pragma clang diagnostic ignored "-Wsign-compare"
#pragma clang diagnostic ignored "-Wlogical-op-parantheses"
#endif

#include <algorithm>
#include <chrono>
#include <string>
Expand Down Expand Up @@ -2489,4 +2497,8 @@ void TextEditor::UndoRecord::Redo(TextEditor* aEditor) {

aEditor->mState = mAfter;
aEditor->EnsureCursorVisible();
}
}

#if defined(__clang__)
#pragma clang diagnostic pop
#endif
2 changes: 1 addition & 1 deletion Engine/SceneDeserializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ void SceneDeserializer::Entities::DefaultDeserializePerspectiveCameraComponent(t
PerspectiveCameraComponent perspective{ entity, std::move(camera) };
scene.InsertComponent<PerspectiveCameraComponent>(perspective.GetEntity(), std::move(perspective));
}
void SceneDeserializer::Entities::DefaultDeserializeUserDefinedComponents(tinyxml2::XMLElement& componentNode, Scene& scene, Entity entity, const std::string& name) {}
void SceneDeserializer::Entities::DefaultDeserializeUserDefinedComponents([[maybe_unused]] tinyxml2::XMLElement& componentNode, [[maybe_unused]] Scene& scene, [[maybe_unused]] Entity entity, [[maybe_unused]] const std::string& name) {}

int SceneDeserializer::Helpers::DeserializeEnum(const tinyxml2::XMLElement& property) {
return property.IntAttribute("value");
Expand Down
10 changes: 10 additions & 0 deletions Launcher/FileDialog.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
// This is external code. Disabling warnings.
#if defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunsequenced" // Disable -Wunsequenced, https://easings.net/#easeOutBounce
#endif

#include <Launcher/FileDialog.hpp>

#include <fstream>
Expand Down Expand Up @@ -1532,4 +1538,8 @@ static const unsigned int folder_icon[] = {
#ifndef _WIN32
static const char* GetDefaultFolderIcon() { return (const char*) &folder_icon[0]; }
static const char* GetDefaultFileIcon() { return (const char*) &file_icon[0]; }
#endif

#if defined(__clang__)
#pragma clang diagnostic pop
#endif

0 comments on commit 0c5f80a

Please sign in to comment.