From 150da2b094976ccc277446efe7ccb061533b1ab5 Mon Sep 17 00:00:00 2001 From: Kenton Varda <kenton@sandstorm.io> Date: Sun, 10 Jun 2018 15:13:09 -0700 Subject: [PATCH] Adjust fallthrough comments to satisfy GCC7's -Wimplicit-fallthrough. If we were using C++17, we could use [[fallthrough]] instead... but we are not. --- c++/src/capnp/compiler/compiler.c++ | 9 +++------ c++/src/capnp/compiler/node-translator.c++ | 5 ++--- c++/src/capnp/dynamic.c++ | 1 + c++/src/kj/encoding.c++ | 5 +++++ c++/src/kj/filesystem-disk-unix.c++ | 1 + c++/src/kj/hash.c++ | 2 ++ 6 files changed, 14 insertions(+), 9 deletions(-) diff --git a/c++/src/capnp/compiler/compiler.c++ b/c++/src/capnp/compiler/compiler.c++ index cc408269..f20ddae7 100644 --- a/c++/src/capnp/compiler/compiler.c++ +++ b/c++/src/capnp/compiler/compiler.c++ @@ -520,8 +520,7 @@ kj::Maybe<Compiler::Node::Content&> Compiler::Node::getContent(Content::State mi } content.advanceState(Content::EXPANDED); - // no break - } + } // fallthrough case Content::EXPANDED: { if (minimumState <= Content::EXPANDED) break; @@ -584,8 +583,7 @@ kj::Maybe<Compiler::Node::Content&> Compiler::Node::getContent(Content::State mi })); content.advanceState(Content::BOOTSTRAP); - // no break - } + } // fallthrough case Content::BOOTSTRAP: { if (minimumState <= Content::BOOTSTRAP) break; @@ -597,8 +595,7 @@ kj::Maybe<Compiler::Node::Content&> Compiler::Node::getContent(Content::State mi content.sourceInfo = kj::mv(nodeSet.sourceInfo); content.advanceState(Content::FINISHED); - // no break - } + } // fallthrough case Content::FINISHED: break; diff --git a/c++/src/capnp/compiler/node-translator.c++ b/c++/src/capnp/compiler/node-translator.c++ index 48ec3a30..a5918530 100644 --- a/c++/src/capnp/compiler/node-translator.c++ +++ b/c++/src/capnp/compiler/node-translator.c++ @@ -997,7 +997,7 @@ bool NodeTranslator::BrandedDecl::compileAsType( addError(errorReporter, "As of Cap'n Proto 0.4, 'Object' has been renamed to 'AnyPointer'. Sorry for the " "inconvenience, and thanks for being an early adopter. :)"); - // no break + // fallthrough case Declaration::BUILTIN_ANY_POINTER: target.initAnyPointer().initUnconstrained().setAnyKind(); return true; @@ -2741,8 +2741,7 @@ kj::Maybe<Orphan<DynamicValue>> ValueTranslator::compileValue(Expression::Reader return kj::mv(result); } - // No break -- value is positive, so we can just go on to the uint case below. - } + } // fallthrough -- value is positive, so we can just go on to the uint case below. case DynamicValue::UINT: { uint64_t maxValue = 0; diff --git a/c++/src/capnp/dynamic.c++ b/c++/src/capnp/dynamic.c++ index fa60e251..7fb0ea00 100644 --- a/c++/src/capnp/dynamic.c++ +++ b/c++/src/capnp/dynamic.c++ @@ -740,6 +740,7 @@ DynamicValue::Builder DynamicStruct::Builder::init(StructSchema::Field field, ui (uint)type.which()); break; } + KJ_UNREACHABLE; } case schema::Field::GROUP: diff --git a/c++/src/kj/encoding.c++ b/c++/src/kj/encoding.c++ index e8211b10..266e00fb 100644 --- a/c++/src/kj/encoding.c++ +++ b/c++/src/kj/encoding.c++ @@ -728,6 +728,7 @@ int base64_encode_block(const char* plaintext_in, int length_in, result = (fragment & 0x0fc) >> 2; *codechar++ = base64_encode_value(result); result = (fragment & 0x003) << 4; + // fallthrough case step_B: if (plainchar == plaintextend) { state_in->result = result; @@ -738,6 +739,7 @@ int base64_encode_block(const char* plaintext_in, int length_in, result |= (fragment & 0x0f0) >> 4; *codechar++ = base64_encode_value(result); result = (fragment & 0x00f) << 2; + // fallthrough case step_C: if (plainchar == plaintextend) { state_in->result = result; @@ -907,6 +909,7 @@ int base64_decode_block(const char* code_in, const int length_in, ERROR_IF(fragment < -1); } while (fragment < 0); *plainchar = (fragment & 0x03f) << 2; + // fallthrough case step_b: do { if (codechar == code_in+length_in) { @@ -924,6 +927,7 @@ int base64_decode_block(const char* code_in, const int length_in, } while (fragment < 0); *plainchar++ |= (fragment & 0x030) >> 4; *plainchar = (fragment & 0x00f) << 4; + // fallthrough case step_c: do { if (codechar == code_in+length_in) { @@ -943,6 +947,7 @@ int base64_decode_block(const char* code_in, const int length_in, ERROR_IF(state_in->nPaddingBytesSeen > 0); *plainchar++ |= (fragment & 0x03c) >> 2; *plainchar = (fragment & 0x003) << 6; + // fallthrough case step_d: do { if (codechar == code_in+length_in) { diff --git a/c++/src/kj/filesystem-disk-unix.c++ b/c++/src/kj/filesystem-disk-unix.c++ index 89867391..41173051 100644 --- a/c++/src/kj/filesystem-disk-unix.c++ +++ b/c++/src/kj/filesystem-disk-unix.c++ @@ -936,6 +936,7 @@ public: // Retry, but make sure we don't try to create the parent again. return tryReplaceNode(path, mode - WriteMode::CREATE_PARENT, kj::mv(tryCreate)); } + // fallthrough default: KJ_FAIL_SYSCALL("create(path)", error, path) { return false; } } else { diff --git a/c++/src/kj/hash.c++ b/c++/src/kj/hash.c++ index 1c30fc26..ec57bf92 100644 --- a/c++/src/kj/hash.c++ +++ b/c++/src/kj/hash.c++ @@ -47,8 +47,10 @@ uint HashCoder::operator*(ArrayPtr<const byte> s) const { switch (len) { case 3: h ^= data[2] << 16; + // fallthrough case 2: h ^= data[1] << 8; + // fallthrough case 1: h ^= data[0]; h *= m; -- 2.18.0