Skip to content

[GEN][ZH] Annotate fallthrough between various switch case labels #1085

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

Merged
merged 1 commit into from
Jun 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Core/Libraries/Source/WWVegas/WWLib/always.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
// TheSuperHackers @compile feliwir 17/04/2025 include utility macros for cross-platform compatibility
#include <Utility/compat.h>
#include <Utility/stdint_adapter.h>

#include <Utility/CppMacros.h>

// Disable warning about exception handling not being enabled. It's used as part of STL - in a part of STL we don't use.
Expand Down
10 changes: 4 additions & 6 deletions Dependencies/Utility/Utility/CppMacros.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@

#if __cplusplus >= 201703L
#define NOEXCEPT_17 noexcept
#define REGISTER
#define FALLTHROUGH [[fallthrough]]
#else
#define NOEXCEPT_17
#define REGISTER register
#define FALLTHROUGH
#endif

// noexcept for methods of IUNKNOWN interface
Expand All @@ -38,12 +42,6 @@
#define CPP_11(code)
#endif

#if __cplusplus >= 201703L
#define REGISTER
#else
#define REGISTER register
#endif

#if __cplusplus < 201103L
#define static_assert(expr, msg)
#endif
2 changes: 2 additions & 0 deletions Generals/Code/GameEngine/Source/Common/RandomValue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@ Real GameClientRandomVariable::getValue( void ) const
if (m_low == m_high) {
return m_low;
} // else return as though a UNIFORM.
FALLTHROUGH;

case UNIFORM:
return GameClientRandomValueReal( m_low, m_high );
Expand Down Expand Up @@ -427,6 +428,7 @@ Real GameLogicRandomVariable::getValue( void ) const
if (m_low == m_high) {
return m_low;
} // else return as though a UNIFORM.
FALLTHROUGH;

case UNIFORM:
return GameLogicRandomValueReal( m_low, m_high );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1877,20 +1877,23 @@ void grabSinglePlayerInfo( void )
{
Bool isFriend = TRUE;

// set the string we'll be compairing to
// set the string we'll be comparing to
switch (j) {
case USA_ENEMY:
isFriend = FALSE;
FALLTHROUGH;
case USA_FRIEND:
side.set("America");
break;
case CHINA_ENEMY:
isFriend = FALSE;
FALLTHROUGH;
case CHINA_FRIEND:
side.set("China");
break;
case GLA_ENEMY:
isFriend = FALSE;
isFriend = FALSE;
Copy link

Choose a reason for hiding this comment

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

Seems odd that it thinks there was a change here.

Choose a reason for hiding this comment

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

Seems odd that it thinks there was a change here.

There's a tab after it in the original line.

FALLTHROUGH;
case GLA_FRIEND:
side.set("GLA");
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ void FlashTransition::update( Int frame )
} // end if

}
FALLTHROUGH;

case FLASHTRANSITION_FADE_IN_2:
case FLASHTRANSITION_FADE_IN_3:
{
Expand Down Expand Up @@ -810,8 +812,8 @@ void ScaleUpTransition::update( Int frame )
TheAudio->addAudioEvent( &buttonClick );
} // end if


}
FALLTHROUGH;

case SCALEUPTRANSITION_2:
case SCALEUPTRANSITION_3:
Expand Down Expand Up @@ -933,8 +935,8 @@ void ScoreScaleUpTransition::update( Int frame )
TheAudio->addAudioEvent( &buttonClick );
} // end if


}
FALLTHROUGH;

case SCORESCALEUPTRANSITION_2:
case SCORESCALEUPTRANSITION_3:
Comment on lines 941 to 942
Copy link

Choose a reason for hiding this comment

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

I am surprised it does not warn about these cases falling through.

Expand Down
2 changes: 2 additions & 0 deletions Generals/Code/GameEngine/Source/GameClient/GameText.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,7 @@ void GameTextManager::readToEndOfQuote( File *file, Char *in, Char *out, Char *w
}

state = 1;
FALLTHROUGH;
case 1:
if ( ( ch >= 'a' && ch <= 'z') || ( ch >= 'A' && ch <='Z') || (ch >= '0' && ch <= '9') || ch == '_' )
{
Expand All @@ -638,6 +639,7 @@ void GameTextManager::readToEndOfQuote( File *file, Char *in, Char *out, Char *w
break;
}
state = 2;
FALLTHROUGH;
case 2:
break;
Comment on lines +642 to 644
Copy link

Choose a reason for hiding this comment

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

State is not used outside of this function so this seems a bit redundant, case 2 could be removed and a break added at the end of case 1.

Copy link
Author

Choose a reason for hiding this comment

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

You are probably right. I think the change as is is sufficient for now, so it is in line with the title of this change.

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ GameMessageDisposition WindowTranslator::translateGameMessage(const GameMessage
//If we release the button outside
forceKeepMessage = TRUE;
}
//FALL THROUGH INTENTIONALLY!
FALLTHROUGH; //FALL THROUGH INTENTIONALLY!
}
case GameMessage::MSG_RAW_MOUSE_POSITION:
case GameMessage::MSG_RAW_MOUSE_LEFT_BUTTON_DOWN:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -494,28 +494,28 @@ StateReturnType HackInternetState::update()
{
break;
}
//If entry missing, fall through!
FALLTHROUGH; //If entry missing, fall through!
case LEVEL_ELITE:
amount = ai->getEliteCashAmount();
if( amount )
{
break;
}
//If entry missing, fall through!
FALLTHROUGH; //If entry missing, fall through!
case LEVEL_VETERAN:
amount = ai->getVeteranCashAmount();
if( amount )
{
break;
}
//If entry missing, fall through!
FALLTHROUGH; //If entry missing, fall through!
case LEVEL_REGULAR:
amount = ai->getRegularCashAmount();
if( amount )
{
break;
}
//If entry missing, fall through!
FALLTHROUGH; //If entry missing, fall through!
default:
amount = 1;
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2216,7 +2216,7 @@ void JetAIUpdate::aiDoCommand(const AICommandParms* parms)
if (isParkedAt(parms->m_obj))
return;

// else fall thru to the default case!
FALLTHROUGH; // else fall thru to the default case!

default:
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,8 @@ UpdateSleepTime MissileAIUpdate::update()
{
break;
}
FALLTHROUGH;

case IGNITION:
doIgnitionState();
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1776,7 +1776,7 @@ void Parameter::qualify(const AsciiString& qualifier,
if (m_string == THIS_TEAM) {
break;
}
/// otherwise drop down & qualify.
FALLTHROUGH; /// otherwise drop down & qualify.
case SCRIPT:
case COUNTER:
case FLAG:
Expand Down
6 changes: 3 additions & 3 deletions Generals/Code/Libraries/Source/WWVegas/WW3D2/meshmdlio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -344,23 +344,23 @@ WW3DErrorType MeshModelClass::Load_W3D(ChunkLoadClass & cload)
Set_Flag (PRELIT_LIGHTMAP_MULTI_TEXTURE, true);
break;
}
// Else fall thru...
FALLTHROUGH; // Else fall thru...

case WW3D::PRELIT_MODE_LIGHTMAP_MULTI_PASS:
if (context->Header.Attributes & W3D_MESH_FLAG_PRELIT_LIGHTMAP_MULTI_PASS) {
context->PrelitChunkID = W3D_CHUNK_PRELIT_LIGHTMAP_MULTI_PASS;
Set_Flag (PRELIT_LIGHTMAP_MULTI_PASS, true);
break;
}
// Else fall thru...
FALLTHROUGH; // Else fall thru...

case WW3D::PRELIT_MODE_VERTEX:
if (context->Header.Attributes & W3D_MESH_FLAG_PRELIT_VERTEX) {
context->PrelitChunkID = W3D_CHUNK_PRELIT_VERTEX;
Set_Flag (PRELIT_VERTEX, true);
break;
}
// Else fall thru...
FALLTHROUGH; // Else fall thru...

default:

Expand Down
2 changes: 2 additions & 0 deletions GeneralsMD/Code/GameEngine/Source/Common/RandomValue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@ Real GameClientRandomVariable::getValue( void ) const
if (m_low == m_high) {
return m_low;
} // else return as though a UNIFORM.
FALLTHROUGH;

case UNIFORM:
return GameClientRandomValueReal( m_low, m_high );
Expand Down Expand Up @@ -427,6 +428,7 @@ Real GameLogicRandomVariable::getValue( void ) const
if (m_low == m_high) {
return m_low;
} // else return as though a UNIFORM.
FALLTHROUGH;

case UNIFORM:
return GameLogicRandomValueReal( m_low, m_high );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2145,20 +2145,23 @@ void grabSinglePlayerInfo( void )
{
Bool isFriend = TRUE;

// set the string we'll be compairing to
// set the string we'll be comparing to
switch (j) {
case USA_ENEMY:
isFriend = FALSE;
FALLTHROUGH;
case USA_FRIEND:
side.set("USA");
break;
case CHINA_ENEMY:
isFriend = FALSE;
FALLTHROUGH;
case CHINA_FRIEND:
side.set("China");
break;
case GLA_ENEMY:
isFriend = FALSE;
isFriend = FALSE;
FALLTHROUGH;
case GLA_FRIEND:
side.set("GLA");
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ void FlashTransition::update( Int frame )
} // end if

}
FALLTHROUGH;

case FLASHTRANSITION_FADE_IN_2:
case FLASHTRANSITION_FADE_IN_3:
Comment on lines +145 to 148
Copy link

Choose a reason for hiding this comment

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

Same as the score scaleup, im surprised it does not complain here, unless it just optimises away empty cases?

Copy link
Author

Choose a reason for hiding this comment

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

Yes it looks like the static analyzer does not care about the fallthrough annotation when there is no body behind the switch case label. It is a very common pattern and I think fallthrough is expected implicitly in this case, so requires no annotation to be clear.

{
Expand Down Expand Up @@ -810,8 +812,8 @@ void ScaleUpTransition::update( Int frame )
TheAudio->addAudioEvent( &buttonClick );
} // end if


}
FALLTHROUGH;

case SCALEUPTRANSITION_2:
case SCALEUPTRANSITION_3:
Expand Down Expand Up @@ -933,8 +935,8 @@ void ScoreScaleUpTransition::update( Int frame )
TheAudio->addAudioEvent( &buttonClick );
} // end if


}
FALLTHROUGH;

case SCORESCALEUPTRANSITION_2:
case SCORESCALEUPTRANSITION_3:
Expand Down
2 changes: 2 additions & 0 deletions GeneralsMD/Code/GameEngine/Source/GameClient/GameText.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,7 @@ void GameTextManager::readToEndOfQuote( File *file, Char *in, Char *out, Char *w
}

state = 1;
FALLTHROUGH;
case 1:
if ( ( ch >= 'a' && ch <= 'z') || ( ch >= 'A' && ch <='Z') || (ch >= '0' && ch <= '9') || ch == '_' )
{
Expand All @@ -638,6 +639,7 @@ void GameTextManager::readToEndOfQuote( File *file, Char *in, Char *out, Char *w
break;
}
state = 2;
FALLTHROUGH;
case 2:
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3704,7 +3704,7 @@ GameMessageDisposition CommandTranslator::translateGameMessage(const GameMessage

break;
}
//intentional fall through
FALLTHROUGH; //intentional fall through
}
case GameMessage::MSG_MOUSE_RIGHT_CLICK:
{
Expand Down Expand Up @@ -3767,7 +3767,7 @@ GameMessageDisposition CommandTranslator::translateGameMessage(const GameMessage

break;
}
//intentional fall through
FALLTHROUGH; //intentional fall through
}
case GameMessage::MSG_MOUSE_LEFT_CLICK:
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ GameMessageDisposition WindowTranslator::translateGameMessage(const GameMessage
//If we release the button outside
forceKeepMessage = TRUE;
}
//FALL THROUGH INTENTIONALLY!
FALLTHROUGH; //FALL THROUGH INTENTIONALLY!
}
case GameMessage::MSG_RAW_MOUSE_POSITION:
case GameMessage::MSG_RAW_MOUSE_LEFT_BUTTON_DOWN:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -506,28 +506,28 @@ StateReturnType HackInternetState::update()
{
break;
}
//If entry missing, fall through!
FALLTHROUGH; //If entry missing, fall through!
case LEVEL_ELITE:
amount = ai->getEliteCashAmount();
if( amount )
{
break;
}
//If entry missing, fall through!
FALLTHROUGH; //If entry missing, fall through!
case LEVEL_VETERAN:
amount = ai->getVeteranCashAmount();
if( amount )
{
break;
}
//If entry missing, fall through!
FALLTHROUGH; //If entry missing, fall through!
case LEVEL_REGULAR:
amount = ai->getRegularCashAmount();
if( amount )
{
break;
}
//If entry missing, fall through!
FALLTHROUGH; //If entry missing, fall through!
default:
amount = 1;
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2450,7 +2450,7 @@ void JetAIUpdate::aiDoCommand(const AICommandParms* parms)
if (isParkedAt(parms->m_obj))
return;

// else fall thru to the default case!
FALLTHROUGH; // else fall thru to the default case!

default:
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,8 @@ UpdateSleepTime MissileAIUpdate::update()
{
break;
}
FALLTHROUGH;

case IGNITION:
doIgnitionState();
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ UpdateSleepTime SpecialAbilityUpdate::update( void )
// it's been captured by a colleague! we should stop.
shouldAbort = TRUE;
}
//deliberately falling through...
FALLTHROUGH; //deliberately falling through...
}
case SPECIAL_BLACKLOTUS_STEAL_CASH_HACK:
case SPECIAL_BOOBY_TRAP:
Expand Down Expand Up @@ -309,7 +309,7 @@ UpdateSleepTime SpecialAbilityUpdate::update( void )
{
if ( target->isKindOf( KINDOF_STRUCTURE ) )
shouldAbort = TRUE;
//deliberately falling through
FALLTHROUGH; //deliberately falling through
}
case SPECIAL_BLACKLOTUS_DISABLE_VEHICLE_HACK:
{
Expand Down
Loading
Loading