From 48d83b3debf0427d76e169bdb939e02c1e10987a Mon Sep 17 00:00:00 2001 From: Thomas Van Lenten Date: Mon, 27 Jan 2025 14:04:13 -0800 Subject: [PATCH] [ObjC] Fix up some sign related warnings. The api signatures aren't changed, just internal casting it used to avoid making an API change which could be considered breaking. PiperOrigin-RevId: 720300558 --- objectivec/GPBDescriptor.m | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/objectivec/GPBDescriptor.m b/objectivec/GPBDescriptor.m index 29fdbded0e8eb..1d9e2dff6ee0c 100644 --- a/objectivec/GPBDescriptor.m +++ b/objectivec/GPBDescriptor.m @@ -100,11 +100,11 @@ + (instancetype)allocDescriptorForClass:(Class)messageClass // Compute the unknown flags by this version of the runtime and then check the passed in flags // (from the generated code) to detect when sources from a newer version are being used with an // older runtime. - GPBDescriptorInitializationFlags unknownFlags = - ~(GPBDescriptorInitializationFlag_FieldsWithDefault | - GPBDescriptorInitializationFlag_WireFormat | GPBDescriptorInitializationFlag_UsesClassRefs | - GPBDescriptorInitializationFlag_Proto3OptionalKnown | - GPBDescriptorInitializationFlag_ClosedEnumSupportKnown); + GPBDescriptorInitializationFlags unknownFlags = (GPBDescriptorInitializationFlags)(~( + GPBDescriptorInitializationFlag_FieldsWithDefault | + GPBDescriptorInitializationFlag_WireFormat | GPBDescriptorInitializationFlag_UsesClassRefs | + GPBDescriptorInitializationFlag_Proto3OptionalKnown | + GPBDescriptorInitializationFlag_ClosedEnumSupportKnown)); if ((flags & unknownFlags) != 0) { GPBRuntimeMatchFailure(); } @@ -144,10 +144,10 @@ + (instancetype)allocDescriptorForClass:(Class)messageClass } // No real value in checking all the fields individually, just check the combined flags at the // end. - GPBFieldFlags unknownFieldFlags = - ~(GPBFieldRequired | GPBFieldRepeated | GPBFieldPacked | GPBFieldOptional | - GPBFieldHasDefaultValue | GPBFieldClearHasIvarOnZero | GPBFieldTextFormatNameCustom | - GPBFieldHasEnumDescriptor | GPBFieldMapKeyMask | GPBFieldClosedEnum); + GPBFieldFlags unknownFieldFlags = (GPBFieldFlags)(~( + GPBFieldRequired | GPBFieldRepeated | GPBFieldPacked | GPBFieldOptional | + GPBFieldHasDefaultValue | GPBFieldClearHasIvarOnZero | GPBFieldTextFormatNameCustom | + GPBFieldHasEnumDescriptor | GPBFieldMapKeyMask | GPBFieldClosedEnum)); if ((mergedFieldFlags & unknownFieldFlags) != 0) { GPBRuntimeMatchFailure(); } @@ -203,7 +203,8 @@ - (void)setupOneofs:(const char **)oneofNames firstHasIndex:(int32_t)firstHasIndex { NSCAssert(firstHasIndex < 0, @"Should always be <0"); NSMutableArray *oneofs = [[NSMutableArray alloc] initWithCapacity:count]; - for (uint32_t i = 0, hasIndex = firstHasIndex; i < count; ++i, --hasIndex) { + int32_t hasIndex = firstHasIndex; + for (uint32_t i = 0; i < count; ++i, --hasIndex) { const char *name = oneofNames[i]; NSArray *fieldsForOneof = NewFieldsArrayForHasIndex(hasIndex, fields_); NSCAssert(fieldsForOneof.count > 0, @"No fields for this oneof? (%s:%d)", name, hasIndex); @@ -231,7 +232,7 @@ - (void)setupExtraTextInfo:(const char *)extraTextFormatInfo { - (void)setupExtensionRanges:(const GPBExtensionRange *)ranges count:(int32_t)count { extensionRanges_ = ranges; - extensionRangesCount_ = count; + extensionRangesCount_ = (uint32_t)count; } - (void)setupContainingMessageClass:(Class)messageClass { @@ -632,7 +633,7 @@ - (NSString *)textFormatName { return nil; } const uint8_t *extraTextFormatInfo = [extraInfoValue pointerValue]; - return GPBDecodeTextFormatName(extraTextFormatInfo, GPBFieldNumber(self), self.name); + return GPBDecodeTextFormatName(extraTextFormatInfo, (int32_t)GPBFieldNumber(self), self.name); } // The logic here has to match SetCommonFieldVariables() from @@ -714,7 +715,7 @@ + (instancetype)allocDescriptorForName:(NSString *)name // (from the generated code) to detect when sources from a newer version are being used with an // older runtime. GPBEnumDescriptorInitializationFlags unknownFlags = - ~(GPBEnumDescriptorInitializationFlag_IsClosed); + (GPBEnumDescriptorInitializationFlags)(~(GPBEnumDescriptorInitializationFlag_IsClosed)); if ((flags & unknownFlags) != 0) { GPBRuntimeMatchFailure(); } @@ -927,8 +928,8 @@ - (instancetype)initWithExtensionDescription:(GPBExtensionDescription *)desc // Compute the unknown options by this version of the runtime and then check the passed in // descriptor's options (from the generated code) to detect when sources from a newer version are // being used with an older runtime. - GPBExtensionOptions unknownOptions = - ~(GPBExtensionRepeated | GPBExtensionPacked | GPBExtensionSetWireFormat); + GPBExtensionOptions unknownOptions = (GPBExtensionOptions)(~( + GPBExtensionRepeated | GPBExtensionPacked | GPBExtensionSetWireFormat)); if ((desc->options & unknownOptions) != 0) { GPBRuntimeMatchFailure(); } @@ -996,7 +997,7 @@ - (const char *)singletonNameC { } - (uint32_t)fieldNumber { - return description_->fieldNumber; + return (uint32_t)(description_->fieldNumber); } - (GPBDataType)dataType {