Skip to content

Commit

Permalink
Eliminate -Wimplicit-fallthrough triggers
Browse files Browse the repository at this point in the history
For each nontrivial `switch` fallthrough, either insert a missing `break` or annotate it as an intended fallthrough. This quashes -Wimplicit-fallthrough, which isn’t an error today but will be soon.

	Change on 2018/07/18 by bbaren <bbaren@google.com>

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=205158031
  • Loading branch information
bbarenblat authored and Tom Ball committed Jul 31, 2018
1 parent d08db63 commit 401ee7a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
6 changes: 3 additions & 3 deletions protobuf/runtime/src/com/google/protobuf/GeneratedMessage.mm
Expand Up @@ -1443,7 +1443,7 @@ static BOOL ReadMapEntryField(
return stream->ReadRetainedNSString(&value->valueId);
case ComGoogleProtobufDescriptors_FieldDescriptor_Type_Enum_GROUP:
isGroup = YES;
// fall through.
FALLTHROUGH_INTENDED;
case ComGoogleProtobufDescriptors_FieldDescriptor_Type_Enum_MESSAGE: {
ComGoogleProtobufGeneratedMessage *newMsg = CGPNewMessage(field->valueType_);
if (!(isGroup ?
Expand Down Expand Up @@ -1554,7 +1554,7 @@ static BOOL MergeExtensionValueFromStream(
return YES;
case ComGoogleProtobufDescriptors_FieldDescriptor_Type_Enum_GROUP:
isGroup = YES;
// fall through.
FALLTHROUGH_INTENDED;
case ComGoogleProtobufDescriptors_FieldDescriptor_Type_Enum_MESSAGE:
{
CGPDescriptor *fieldType = field->valueType_;
Expand Down Expand Up @@ -1806,7 +1806,7 @@ static BOOL MergeFieldFromStream(
return YES;
case ComGoogleProtobufDescriptors_FieldDescriptor_Type_Enum_GROUP:
isGroup = YES;
// fall through.
FALLTHROUGH_INTENDED;
case ComGoogleProtobufDescriptors_FieldDescriptor_Type_Enum_MESSAGE:
{
CGPDescriptor *fieldType = field->valueType_;
Expand Down
14 changes: 14 additions & 0 deletions protobuf/runtime/src/com/google/protobuf/common.h
Expand Up @@ -46,4 +46,18 @@ typedef uint16_t uint16;
typedef uint32_t uint32;
typedef uint64_t uint64;

#if defined(__clang__) && defined(__has_warning)
#if __has_feature(cxx_attributes) && __has_warning("-Wimplicit-fallthrough")
#define FALLTHROUGH_INTENDED [[clang::fallthrough]]
#endif
#elif defined(__GNUC__) && __GNUC__ >= 7
#define FALLTHROUGH_INTENDED [[gnu::fallthrough]]
#endif

#ifndef FALLTHROUGH_INTENDED
#define FALLTHROUGH_INTENDED \
do { \
} while (0)
#endif

#endif // __ComGoogleProtobufCommon_H__

0 comments on commit 401ee7a

Please sign in to comment.