Skip to content

Conversation

@JohnsterID
Copy link

i686-w64-mingw32-gcc build broke with commit d38f692. Inline ternary works for all builds.

Changes:

  • Replace min(m_bits.size(), sizeof(val) * 8) with inline ternary operator
  • Avoids dependency on or always.h
  • Fixes both Generals and GeneralsMD BitFlags.h files

This resolves:

  • MinGW-w64 GCC 14 error: 'min' was not declared in this scope
  • VC6 error: syntax error : '::' if using std::min
  • MSVC error: '(' : illegal token on right side of '::' if using std::min

Root cause analysis:

  • Original code used unqualified min() expecting always.h's template
  • BitFlags.h doesn't include always.h (it's in WWVegas, not GameEngine)
  • VC6's doesn't have std::min (only min_element)
  • VC6's <minmax.h> has min() macro, but NOMINMAX disables it
  • Inline ternary is simple, portable, and VC6-compatible

i686-w64-mingw32-gcc build broke with commit d38f692. Inline ternary works for all builds.

Changes:
- Replace min(m_bits.size(), sizeof(val) * 8) with inline ternary operator
- Avoids dependency on <algorithm> or always.h
- Fixes both Generals and GeneralsMD BitFlags.h files

This resolves:
- MinGW-w64 GCC 14 error: 'min' was not declared in this scope
- VC6 error: syntax error : '::' if using std::min
- MSVC error: '(' : illegal token on right side of '::' if using std::min

Root cause analysis:
- Original code used unqualified min() expecting always.h's template
- BitFlags.h doesn't include always.h (it's in WWVegas, not GameEngine)
- VC6's <algorithm> doesn't have std::min (only min_element)
- VC6's <minmax.h> has min() macro, but NOMINMAX disables it
- Inline ternary is simple, portable, and VC6-compatible
@JohnsterID JohnsterID force-pushed the bugfix/bitflags-std-min branch from 0bc32e1 to 2121bf2 Compare January 24, 2026 07:44
{
UnsignedInt val = 0;
const UnsignedInt count = min(m_bits.size(), sizeof(val) * 8);
const UnsignedInt count = (m_bits.size() < sizeof(val) * 8) ? m_bits.size() : sizeof(val) * 8;
Copy link

Choose a reason for hiding this comment

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

Instead, what do we need to do to get min into this file?

The new code is harder to read.

Choose a reason for hiding this comment

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

I agree.

If it is an issue that min() cannot be found, then there should be imho a macro for it in the case of minGW.

Copy link
Author

Choose a reason for hiding this comment

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

Better alternative: #2183

@xezon xezon added Minor Severity: Minor < Major < Critical < Blocker CompileBug Bug at compile time ThisProject The issue was introduced by this project, or this task is specific to this project labels Jan 24, 2026
@xezon xezon closed this Jan 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CompileBug Bug at compile time Minor Severity: Minor < Major < Critical < Blocker ThisProject The issue was introduced by this project, or this task is specific to this project

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants