Fix -Wimplicit-fallthrough warnings from GCC 8

Adds `FALLTHROUGH` macro to specify when a fallthrough is intentional.
Can be replaced by `[[fallthrough]]` if/when we switch to C++17.

The warning is now enabled by default for GCC on `extra` warnings level
(part of GCC's `-Wextra`). It's not enabled in Clang's `-Wextra` yet,
but we could enable it manually once we switch to C++11. There's no
equivalent feature in MSVC for now.

Fixes #26135.
This commit is contained in:
Rémi Verschelde 2019-04-05 14:06:16 +02:00
parent e4a96164b6
commit fc370b3feb
18 changed files with 82 additions and 67 deletions

View file

@ -777,7 +777,8 @@ GDScriptParser::Node *GDScriptParser::_parse_expression(Node *p_parent, bool p_s
}
_add_warning(GDScriptWarning::UNASSIGNED_VARIABLE_OP_ASSIGN, -1, identifier.operator String());
}
} // fallthrough
FALLTHROUGH;
}
case GDScriptTokenizer::TK_OP_ASSIGN: {
lv->assignments += 1;
lv->usages--; // Assignment is not really usage
@ -3636,7 +3637,8 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
return;
}
}; //fallthrough to function
FALLTHROUGH;
}
case GDScriptTokenizer::TK_PR_FUNCTION: {
bool _static = false;
@ -4086,7 +4088,8 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
break;
}
}; //fallthrough to use the same
FALLTHROUGH;
}
case Variant::REAL: {
if (tokenizer->get_token() == GDScriptTokenizer::TK_IDENTIFIER && tokenizer->get_token_identifier() == "EASE") {
@ -4511,6 +4514,7 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
#ifdef DEBUG_ENABLED
_add_warning(GDScriptWarning::DEPRECATED_KEYWORD, tokenizer->get_token_line(), "slave", "puppet");
#endif
FALLTHROUGH;
case GDScriptTokenizer::TK_PR_PUPPET: {
//may be fallthrough from export, ignore if so
@ -4578,7 +4582,7 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
continue;
} break;
case GDScriptTokenizer::TK_PR_VAR: {
//variale declaration and (eventual) initialization
// variable declaration and (eventual) initialization
ClassNode::Member member;
@ -5290,7 +5294,8 @@ String GDScriptParser::DataType::to_string() const {
if (!gds_class.empty()) {
return gds_class;
}
} // fallthrough
FALLTHROUGH;
}
case SCRIPT: {
if (is_meta_type) {
return script_type->get_class_name().operator String();
@ -8046,7 +8051,8 @@ void GDScriptParser::_check_block_types(BlockNode *p_block) {
if (cn->value.get_type() == Variant::STRING) {
break;
}
} // falthrough
FALLTHROUGH;
}
default: {
_mark_line_as_safe(statement->line);
_reduce_node_type(statement); // Test for safety anyway