Skip to content

Fix C4709 Warnings In modern VS#7576

Open
TheForce172 wants to merge 9 commits into
scp-fs2open:masterfrom
TheForce172:fix/c4709
Open

Fix C4709 Warnings In modern VS#7576
TheForce172 wants to merge 9 commits into
scp-fs2open:masterfrom
TheForce172:fix/c4709

Conversation

@TheForce172

Copy link
Copy Markdown
Member

@TheForce172
TheForce172 marked this pull request as draft July 7, 2026 22:03
@TheForce172

Copy link
Copy Markdown
Member Author

Drafted pending testing and further discussion

@Goober5000 Goober5000 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

One change, plus two missed sites:
fred2/fredrender.cpp:1429
fred2/fredview.cpp:1466

Plus, if we're going to convert everything, we might as well entirely remove the operator overload in flagset.h, or change it to operator|.

EDIT: Or, as Claude suggested, adding an any_of function.

Comment thread code/particle/volumes/ModelSurfaceVolume.cpp
@BMagnu

BMagnu commented Jul 8, 2026

Copy link
Copy Markdown
Member

I generally agree that replacing the operator with | is probably safer

@Goober5000

Copy link
Copy Markdown
Contributor

Suggested functions, written by Claude:

// Returns true if at least one of the given flags is set.
// Replacement for the flag_combinator subscript idiom (flags[A, B]),
// which trips MSVC warning C4709.
template<typename... Ts>
bool any_of(T first, Ts... rest) const
{
    static_assert((std::is_same<Ts, T>::value && ...),
        "All arguments to any_of() must be flags of the same enum type");
    return (*this)[first] || ((*this)[rest] || ...);
}

// Returns true if none of the given flags are set.
template<typename... Ts>
bool none_of(T first, Ts... rest) const
{
    return !any_of(first, rest...);
}

@Goober5000 Goober5000 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Miscellaneous items. Also, test_flagset.cpp (part of the test project, not always built) still uses the comma.

Comment thread code/ai/aicode.cpp Outdated
Comment thread code/ai/aicode.cpp Outdated
Comment thread code/ai/aicode.cpp Outdated
Comment thread code/ship/ship.h Outdated
Comment thread code/ship/ship.h Outdated
Comment thread code/weapon/weapon.h
Comment thread code/globalincs/flagset.h
@TheForce172
TheForce172 marked this pull request as ready for review July 14, 2026 11:43
@TheForce172
TheForce172 requested a review from Goober5000 July 18, 2026 15:37

@Goober5000 Goober5000 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Two more minor things

Comment thread code/ai/aicode.cpp Outdated
}

if (aip->ai_flags[AI::AI_Flags::No_dynamic, AI::AI_Flags::Kamikaze]) { // If not allowed to pursue dynamic objectives, don't evade. Dumb? Maybe change. -- MK, 3/15/98
if (aip->ai_flags.any_of(AI::AI_Flags::No_dynamic,AI::AI_Flags::Kamikaze)) { // If not allowed to pursue dynamic objectives, don't evade. Dumb? //Maybe change. -- MK, 3/15/98

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Slashes got added to the middle of the comment at the end of the line. The comment ought not to have any changes so the diff will be clean between revisions.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Unfortunately the pre- and post- versions don't match, so there is still a diff in the middle of the comment. There are two spaces before the "Maybe change" sentence.

Comment thread code/ai/aicode.cpp Outdated
aip->last_hit_time = Missiontime;

if (aip->ai_flags[AI::AI_Flags::No_dynamic, AI::AI_Flags::Kamikaze]) // If not allowed to pursue dynamic objectives, don't evade. Dumb? Maybe change. -- MK, 3/15/98
if (aip->ai_flags.any_of(AI::AI_Flags::No_dynamic,AI::AI_Flags::Kamikaze)) // If not allowed to pursue dynamic objectives, don't evade. Dumb? //Maybe change. -- MK, 3/15/98

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same here with the slashes

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Two spaces here too.

@Goober5000 Goober5000 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

In addition to the line endings, the flag_combinator items in flagset.h can now be removed.

Comment thread test/src/globalincs/test_flagset.cpp Outdated

@Goober5000 Goober5000 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nearly there! Looks pretty good overall. Just space fixes on the two comments, and an orphaned struct to be removed.

Comment thread code/globalincs/flagset.h Outdated
};

template<typename TEnum>
struct flag_enum_checker

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This can be removed too, as it's now orphaned.

@TheForce172

Copy link
Copy Markdown
Member Author

What!? Why is clang complaining now and not on the last run?

@Goober5000

Goober5000 commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

That's very odd. Not only did it not flag that line previously, that line can't really be simplified either.

I'd call this a false positive. Adding

// NOLINT(readability-simplify-boolean-expr)

at the end of the line should suppress the warning.

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.

3 participants