Skip to content

Fixed clang 22 error with overloaded operator#1909

Closed
Farmer-Markus wants to merge 1 commit intoReturn-To-The-Roots:masterfrom
Farmer-Markus:master
Closed

Fixed clang 22 error with overloaded operator#1909
Farmer-Markus wants to merge 1 commit intoReturn-To-The-Roots:masterfrom
Farmer-Markus:master

Conversation

@Farmer-Markus
Copy link
Copy Markdown
Contributor

@Farmer-Markus Farmer-Markus commented Apr 1, 2026

Error:

s25client/libs/s25main/ingameWindows/iwAddons.cpp:151:65: error: use of overloaded operator '!=' is ambiguous (with operand types 'AddonGroup' and 'AddonGroup')
  151 |         const bool isVisible = (addon->getGroups() & selection) != AddonGroup(0);
      |                                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^  ~~~~~~~~~~~~~
s25client/libs/s25main/addons/const_addons.h:90:1: note: candidate function has been explicitly deleted
   90 | MAKE_BITSET_STRONG(AddonGroup);
      | ^
s25client/external/libutil/libs/common/include/s25util/enumUtils.h:91:10: note: expanded from macro 'MAKE_BITSET_STRONG'
   91 |     bool operator!=(const Type& lhs, const Type& rhs) = delete;     \
      |          ^
s25client/libs/s25main/ingameWindows/iwAddons.cpp:151:65: note: built-in candidate operator!=(enum AddonGroup, enum AddonGroup)
  151 |         const bool isVisible = (addon->getGroups() & selection) != AddonGroup(0);
      |                                                                 ^
1 error generated.

{
const Addon* addon = ggs.getAddon(i);
const bool isVisible = (addon->getGroups() & selection) != AddonGroup(0);
const bool isVisible = static_cast<unsigned>(addon->getGroups() & selection) != 0;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The intended way was this:

Suggested change
const bool isVisible = static_cast<unsigned>(addon->getGroups() & selection) != 0;
const bool isVisible = bitset::any(addon->getGroups(), selection);

I.e. bitsets shouldn't be compared but only modified or checked unless we find a use case for that.
Or do you see anything I missed?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ups, missed that.
But I don't understand why the MAKE_BITSET_STRONG macro exists.
I mean what's the point of using it? Type safety or to prevent lines like the current one?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A bit of all:

  • Type safety: Only combine enumerators of same enum
  • Typing: Allow combining of enum classes at all w/o static_cast
  • Prevent unwanted operations: bitset != bitset is usually not what you want as you'd likely wanted to test bits or if bitsets overlap (non-empty union)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A bit of all:

* Type safety: Only combine enumerators of same enum

* Typing: Allow combining of enum classes at all w/o `static_cast`

* Prevent unwanted operations: `bitset != bitset` is usually not what you want as you'd likely wanted to test bits or if bitsets overlap (non-empty union)

Ok thanks.

There is no bitset any implementation in enumUtils if that is what you meant.
And I thought my compiler is doing something weird since it just crashes without error messages. Very weird

@Farmer-Markus Farmer-Markus force-pushed the master branch 2 times, most recently from 4b0e5e4 to d9acdbd Compare April 1, 2026 12:13
@Flamefire
Copy link
Copy Markdown
Member

Actually the issue seems to be that you updated the submodule to a different version. The change from libutil is pulled in in #1890 where this issue is avoided too. Run git submodule update to fix your tree :)

@Flamefire Flamefire closed this Apr 1, 2026
@Farmer-Markus
Copy link
Copy Markdown
Contributor Author

Actually the issue seems to be that you updated the submodule to a different version. The change from libutil is pulled in in #1890 where this issue is avoided too. Run git submodule update to fix your tree :)

I see :D
Just saw the bitset::any was available in newer commits of libutils
Thanks for your patience

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

Successfully merging this pull request may close these issues.

2 participants