stage1: make C++ switch fallthrough an error

Make fallthrough an error when compiler supports it. This requires a new
macro that is defined with such compilers to be used as a statement, at
all fallthrough sites:

    switch (...) {
        case 0:
            ...
            ZIG_FALLTHROUGH;
        case 1:
            ...
            break;
        default:
            ...
            break;
    }

If we ever move to C++17 as minimal requirement, then the macro can be
replaced with `[[fallthrough]];` at statement sites.
This commit is contained in:
Michael Dusan
2020-04-01 12:47:50 -04:00
committed by Andrew Kelley
parent 0f1f56bb69
commit 212e2354b8
8 changed files with 28 additions and 7 deletions

View File

@@ -840,6 +840,7 @@ void tokenize(Buf *buf, Tokenization *out) {
t.state = TokenizeStateStart;
continue;
}
break;
case TokenizeStateSawSlash:
switch (c) {
case '/':
@@ -1209,7 +1210,7 @@ void tokenize(Buf *buf, Tokenization *out) {
t.is_trailing_underscore = false;
t.state = TokenizeStateNumber;
}
// fall through
ZIG_FALLTHROUGH;
case TokenizeStateNumber:
{
if (c == '_') {
@@ -1291,7 +1292,7 @@ void tokenize(Buf *buf, Tokenization *out) {
t.is_trailing_underscore = false;
t.state = TokenizeStateFloatFraction;
}
// fall through
ZIG_FALLTHROUGH;
case TokenizeStateFloatFraction:
{
if (c == '_') {
@@ -1350,7 +1351,7 @@ void tokenize(Buf *buf, Tokenization *out) {
t.is_trailing_underscore = false;
t.state = TokenizeStateFloatExponentNumber;
}
// fall through
ZIG_FALLTHROUGH;
case TokenizeStateFloatExponentNumber:
{
if (c == '_') {