From b41ca5ad78e8fca8ed65088250d2c7e0e21239e1 Mon Sep 17 00:00:00 2001 From: phosit Date: Wed, 29 Jan 2025 13:05:53 +0100 Subject: [PATCH] Replace FALLTHROUGH by the standard attribute --- source/gui/ObjectTypes/CInput.cpp | 4 ++-- source/gui/SettingTypes/CGUIString.cpp | 8 ++++---- source/lib/code_annotation.h | 14 +------------- source/lib/sysdep/os/unix/unix.cpp | 6 +++--- source/renderer/TexturedLineRData.cpp | 4 ++-- source/simulation2/components/CCmpUnitMotion.h | 4 ++-- .../ogre3d_preprocessor/OgreGLSLPreprocessor.cpp | 7 +++---- 7 files changed, 17 insertions(+), 30 deletions(-) diff --git a/source/gui/ObjectTypes/CInput.cpp b/source/gui/ObjectTypes/CInput.cpp index 454b7bf358..bc51f4f568 100644 --- a/source/gui/ObjectTypes/CInput.cpp +++ b/source/gui/ObjectTypes/CInput.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2024 Wildfire Games. +/* Copyright (C) 2025 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -328,7 +328,7 @@ void CInput::ManuallyMutableHandleKeyDownEvent(const SDL_Keycode keyCode) } cooked = '\n'; // Change to '\n' and do default: - FALLTHROUGH; + [[fallthrough]]; } default: // Insert a character { diff --git a/source/gui/SettingTypes/CGUIString.cpp b/source/gui/SettingTypes/CGUIString.cpp index 27872be49b..4b04dc6031 100644 --- a/source/gui/SettingTypes/CGUIString.cpp +++ b/source/gui/SettingTypes/CGUIString.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2022 Wildfire Games. +/* Copyright (C) 2025 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -345,7 +345,7 @@ void CGUIString::SetValue(const CStrW& str) LOGERROR("Parameter without value at pos %d '%s'", p, utf8_from_wstring(str)); break; } - FALLTHROUGH; + [[fallthrough]]; case L'=': // parse a quoted parameter if (closing) // We still parse them to make error handling cleaner @@ -372,7 +372,7 @@ void CGUIString::SetValue(const CStrW& str) break; } // NOTE: We do not support \n in tag parameters - FALLTHROUGH; + [[fallthrough]]; default: param.push_back(str[p]); } @@ -437,7 +437,7 @@ void CGUIString::SetValue(const CStrW& str) m_RawString.push_back(L'\n'); break; } - FALLTHROUGH; + [[fallthrough]]; default: ++rawpos; m_RawString.push_back(str[p]); diff --git a/source/lib/code_annotation.h b/source/lib/code_annotation.h index a5bb29ca91..a17ae7271c 100644 --- a/source/lib/code_annotation.h +++ b/source/lib/code_annotation.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2021 Wildfire Games. +/* Copyright (c) 2025 Wildfire Games. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -403,16 +403,4 @@ template char (*ArraySizeDeducer(T (&)[n]))[n]; #define WIDEN2(x) L ## x #define WIDEN(x) WIDEN2(x) -// TODO: Replace this with [[fallthrough]] once we support C++17 -#if __has_cpp_attribute(fallthrough) || defined(__cplusplus) && __cplusplus >= 201703L -# define FALLTHROUGH [[fallthrough]] -#elif __has_cpp_attribute(gnu::fallthrough) -# define FALLTHROUGH [[gnu::fallthrough]] -#elif __has_cpp_attribute(clang::fallthrough) -# define FALLTHROUGH [[clang::fallthrough]] -#else -# define FALLTHROUGH -// TODO: Maybe use __fallthrough for the MSVC code analyzer (also figure out if we need to add some switch when switching to a newer version of VS that supports [[fallthrough]] -#endif - #endif // #ifndef INCLUDED_CODE_ANNOTATION diff --git a/source/lib/sysdep/os/unix/unix.cpp b/source/lib/sysdep/os/unix/unix.cpp index 501516ecd8..eab120a90c 100644 --- a/source/lib/sysdep/os/unix/unix.cpp +++ b/source/lib/sysdep/os/unix/unix.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2021 Wildfire Games. +/* Copyright (c) 2025 Wildfire Games. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -173,7 +173,7 @@ static ErrorReactionInternal try_gui_display_error(const wchar_t* text, bool man { case 103: // Debugger udbg_launch_debugger(); - FALLTHROUGH; + [[fallthrough]]; case 102: // Break if(manual_break) @@ -245,7 +245,7 @@ ErrorReactionInternal sys_display_error(const wchar_t* text, size_t flags) case EOF: case 'd': case 'D': udbg_launch_debugger(); - FALLTHROUGH; + [[fallthrough]]; case 'b': case 'B': if(manual_break) diff --git a/source/renderer/TexturedLineRData.cpp b/source/renderer/TexturedLineRData.cpp index b23b49ea04..e5e929021b 100644 --- a/source/renderer/TexturedLineRData.cpp +++ b/source/renderer/TexturedLineRData.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2024 Wildfire Games. +/* Copyright (C) 2025 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -385,7 +385,7 @@ void CTexturedLineRData::CreateLineCap(const SOverlayTexturedLine& line, const C radius *= 1.5f; // make it a bit sharper (note that we don't use the radius for the butt-end corner points so it should be ok) centerVertex.m_UV.X = 0.480f; // slight visual correction to make the texture match up better at the corner points } - FALLTHROUGH; + [[fallthrough]]; case SOverlayTexturedLine::LINECAP_ROUND: { // Draw a rounded line cap in the 3D plane of the line specified by the two corner points and the normal vector of the diff --git a/source/simulation2/components/CCmpUnitMotion.h b/source/simulation2/components/CCmpUnitMotion.h index e5963788f9..98311550a1 100644 --- a/source/simulation2/components/CCmpUnitMotion.h +++ b/source/simulation2/components/CCmpUnitMotion.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2023 Wildfire Games. +/* Copyright (C) 2025 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -411,7 +411,7 @@ public: const CMessageValueModification& msgData = static_cast (msg); if (msgData.component != L"UnitMotion") break; - FALLTHROUGH; + [[fallthrough]]; } case MT_OwnershipChanged: { diff --git a/source/third_party/ogre3d_preprocessor/OgreGLSLPreprocessor.cpp b/source/third_party/ogre3d_preprocessor/OgreGLSLPreprocessor.cpp index d3c184e85d..44bb7bc2f9 100644 --- a/source/third_party/ogre3d_preprocessor/OgreGLSLPreprocessor.cpp +++ b/source/third_party/ogre3d_preprocessor/OgreGLSLPreprocessor.cpp @@ -767,7 +767,7 @@ namespace Ogre { case Token::TK_EOS: ErrorHandler(Line, "Unfinished list of arguments", nullptr); - FALLTHROUGH; + [[fallthrough]]; case Token::TK_ERROR: return Token (Token::TK_ERROR); case Token::TK_PUNCTUATION: @@ -874,7 +874,7 @@ namespace Ogre { case Token::TK_EOS: ErrorHandler(Line, "Unfinished list of arguments", nullptr); - FALLTHROUGH; + [[fallthrough]]; case Token::TK_ERROR: return Token (Token::TK_ERROR); @@ -1345,9 +1345,8 @@ namespace Ogre output.AppendNL (empty_lines); empty_lines = 0; } - FALLTHROUGH; // to default + [[fallthrough]]; case Token::TK_WHITESPACE: - // Fallthrough to default default: // Passthrough all other tokens if (output_enabled)