Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecation warning about mixed enums when compiling with C++20 (and newer) #209

Open
mich-dy opened this issue Jan 31, 2025 · 1 comment

Comments

@mich-dy
Copy link

mich-dy commented Jan 31, 2025

I'm using the ImGuiFileDialog in my own project, and I compiled all code with C++20/23/26 to test forward-compatibility.
And I ran into a deprecation warning in the file dialog code when using C++20:

/.../build/_deps/filedialog-src/ImGuiFileDialog.cpp:3997:130: warning: bitwise operation between different enumeration types ‘ImGuiSelectableFlags_’ and ‘ImGuiSelectableFlagsPrivate_’ is deprecated [-Wdeprecated-enum-enum-conversion]
 3997 |                             if (ImGui::Selectable(infos_ptr->fileNameExt.c_str(), &selected, ImGuiSelectableFlags_SpanAllColumns | ImGuiSelectableFlags_SpanAvailWidth)) {

There is no urgent action needed since the code still compiles, but it might break at some point in the future.
So, please see this issue just as a reminder :)

@kyle-paul
Copy link

I encountered the same issue with C++20. The reason is that ImGuiSelectableFlags_SpanAllColumns belongs to the ImGuiSelectableFlags_ enum, while ImGuiSelectableFlags_SpanAvailWidth is part of the ImGuiSelectableFlagsPrivate_ enum. The ImGuiSelectableFlags_ enum has a value range from 0 to 1 << 5, whereas ImGuiSelectableFlagsPrivate_ ranges from 1 << 20 to 1 << 27. Since these ranges do not overlap, performing a bitwise OR operation between these two flags does not cause any logical conflicts.

Here’s how I fixed it:

Use static_cast<int> to ensure compatibility:

static_cast<int>(ImGuiSelectableFlags_SpanAllColumns) | static_cast<int>(ImGuiSelectableFlags_SpanAvailWidth)

You can verify this with the following simple test:

#include <iostream>

int main() {
    int a = 1 << 1;  // 2^1
    std::cout << a << "\n";

    int b = 1 << 24; // 2^24 = 16777216
    std::cout << b << "\n";

    std::cout << (a | b) << "\n";  // 16777218

    int c = static_cast<int>(a) | static_cast<int>(b);  // 16777218
    std::cout << c;

    return 0;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants