Fix C4709 Warnings In modern VS#7576
Conversation
|
Drafted pending testing and further discussion |
There was a problem hiding this comment.
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.
|
I generally agree that replacing the operator with | is probably safer |
|
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
left a comment
There was a problem hiding this comment.
Miscellaneous items. Also, test_flagset.cpp (part of the test project, not always built) still uses the comma.
Goober5000
left a comment
There was a problem hiding this comment.
Two more minor things
| } | ||
|
|
||
| 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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
| 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 |
There was a problem hiding this comment.
Same here with the slashes
Goober5000
left a comment
There was a problem hiding this comment.
In addition to the line endings, the flag_combinator items in flagset.h can now be removed.
Goober5000
left a comment
There was a problem hiding this comment.
Nearly there! Looks pretty good overall. Just space fixes on the two comments, and an orphaned struct to be removed.
| }; | ||
|
|
||
| template<typename TEnum> | ||
| struct flag_enum_checker |
There was a problem hiding this comment.
This can be removed too, as it's now orphaned.
|
What!? Why is clang complaining now and not on the last run? |
|
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 at the end of the line should suppress the warning. |
Fixes https://learn.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-4-c4709?view=msvc-170 errors