From 2cf6ac6c507529884d6b8acfdc42f3bc1826b19d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= <rverschelde@gmail.com>
Date: Sat, 22 Feb 2020 20:47:50 +0100
Subject: Replace FALLTHROUGH macro by C++17 [[fallthrough]]

This attribute is now part of the standard we target so we no longer
need compiler-specific hacks.

Also enables -Wimplicit-fallthrough for Clang now that we can properly
support it. It's already on by default for GCC's -Wextra.

Fixes new warnings raised by Clang's -Wimplicit-fallthrough.
---
 core/io/multiplayer_api.cpp    |  2 +-
 core/packed_data_container.cpp |  4 ++--
 core/typedefs.h                | 22 ----------------------
 core/ustring.cpp               |  1 +
 core/variant_parser.cpp        |  2 +-
 5 files changed, 5 insertions(+), 26 deletions(-)

(limited to 'core')

diff --git a/core/io/multiplayer_api.cpp b/core/io/multiplayer_api.cpp
index 1fcd00c0e4..6a0eeea513 100644
--- a/core/io/multiplayer_api.cpp
+++ b/core/io/multiplayer_api.cpp
@@ -51,7 +51,7 @@ _FORCE_INLINE_ bool _should_call_local(MultiplayerAPI::RPCMode mode, bool is_mas
 		case MultiplayerAPI::RPC_MODE_MASTERSYNC: {
 			if (is_master)
 				r_skip_rpc = true; // I am the master, so skip remote call.
-			FALLTHROUGH;
+			[[fallthrough]];
 		}
 		case MultiplayerAPI::RPC_MODE_REMOTESYNC:
 		case MultiplayerAPI::RPC_MODE_PUPPETSYNC: {
diff --git a/core/packed_data_container.cpp b/core/packed_data_container.cpp
index f23ee30a27..6a4fac971c 100644
--- a/core/packed_data_container.cpp
+++ b/core/packed_data_container.cpp
@@ -225,8 +225,8 @@ uint32_t PackedDataContainer::_pack(const Variant &p_data, Vector<uint8_t> &tmpd
 
 			string_cache[s] = tmpdata.size();
 
-			FALLTHROUGH;
-		};
+			[[fallthrough]];
+		}
 		case Variant::NIL:
 		case Variant::BOOL:
 		case Variant::INT:
diff --git a/core/typedefs.h b/core/typedefs.h
index 174e65cda7..5376b0718a 100644
--- a/core/typedefs.h
+++ b/core/typedefs.h
@@ -335,28 +335,6 @@ struct _GlobalLock {
  */
 #define CAST_INT_TO_UCHAR_PTR(ptr) ((uint8_t *)(uintptr_t)(ptr))
 
-/** Hint for compilers that this fallthrough in a switch is intentional.
- *  Can be replaced by [[fallthrough]] annotation if we move to C++17.
- *  Including conditional support for it for people who set -std=c++17
- *  themselves.
- *  Requires a trailing semicolon when used.
- */
-#if __cplusplus >= 201703L
-#define FALLTHROUGH [[fallthrough]]
-#elif defined(__GNUC__) && __GNUC__ >= 7
-#define FALLTHROUGH __attribute__((fallthrough))
-#elif defined(__llvm__) && __cplusplus >= 201103L && defined(__has_feature)
-#if __has_feature(cxx_attributes) && defined(__has_warning)
-#if __has_warning("-Wimplicit-fallthrough")
-#define FALLTHROUGH [[clang::fallthrough]]
-#endif
-#endif
-#endif
-
-#ifndef FALLTHROUGH
-#define FALLTHROUGH
-#endif
-
 // Home-made index sequence trick, so it can be used everywhere without the costly include of std::tuple.
 // https://stackoverflow.com/questions/15014096/c-index-of-type-during-variadic-template-expansion
 
diff --git a/core/ustring.cpp b/core/ustring.cpp
index c4543b89da..1d4d9c2dfd 100644
--- a/core/ustring.cpp
+++ b/core/ustring.cpp
@@ -2169,6 +2169,7 @@ int64_t String::to_int(const CharType *p_str, int p_len) {
 				} else {
 					break;
 				}
+				[[fallthrough]];
 			}
 			case READING_INT: {
 
diff --git a/core/variant_parser.cpp b/core/variant_parser.cpp
index 059dc161c7..e668374f15 100644
--- a/core/variant_parser.cpp
+++ b/core/variant_parser.cpp
@@ -216,7 +216,7 @@ Error VariantParser::get_token(Stream *p_stream, Token &r_token, int &line, Stri
 				}
 
 				string_name = true;
-				FALLTHROUGH;
+				[[fallthrough]];
 			}
 			case '"': {
 
-- 
cgit v1.2.3