From ad2d5c926bab7af19fa43688b86d368575fd90ce Mon Sep 17 00:00:00 2001 From: Thomas Van Lenten Date: Wed, 30 Sep 2015 13:34:16 -0400 Subject: Support enum forward decls in Objective C++ NS_ENUM changes defintion in Objective C++ based on the C++ spec being compiled with, special case the one situation where it wouldn't support doing a forward decl for the enum. --- objectivec/GPBBootstrap.h | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'objectivec/GPBBootstrap.h') diff --git a/objectivec/GPBBootstrap.h b/objectivec/GPBBootstrap.h index 3dd2de83..c49c7e20 100644 --- a/objectivec/GPBBootstrap.h +++ b/objectivec/GPBBootstrap.h @@ -46,12 +46,20 @@ // Used in the generated code to give sizes to enums. int32_t was chosen based // on the fact that Protocol Buffers enums are limited to this range. -// The complexity and double definition here are so we get the nice name -// for objective C, but also define the name with a trailing underscore so -// the Swift bridge will have one where the names line up to support short -// names since they are scoped to the enum. -// https://developer.apple.com/library/ios/documentation/Swift/Conceptual/BuildingCocoaApps/InteractingWithCAPIs.html#//apple_ref/doc/uid/TP40014216-CH8-XID_11 -#define GPB_ENUM(X) NS_ENUM(int32_t, X) +#if !__has_feature(objc_fixed_enum) + #error All supported Xcode versions should support objc_fixed_enum. +#endif +// If the headers are imported into Objective-C++, we can run into an issue +// where the defintion of NS_ENUM (really CF_ENUM) changes based on the C++ +// standard that is in effect. If it isn't C++11 or higher, the definition +// doesn't allow us to forward declare. We work around this one case by +// providing a local definition. The default case has to use NS_ENUM for the +// magic that is Swift bridging of enums. +#if (__cplusplus && __cplusplus < 201103L) + #define GPB_ENUM(X) enum X : int32_t X; enum X : int32_t +#else + #define GPB_ENUM(X) NS_ENUM(int32_t, X) +#endif // GPB_ENUM_FWD_DECLARE is used for forward declaring enums, ex: // GPB_ENUM_FWD_DECLARE(Foo_Enum) // @property (nonatomic) Foo_Enum value; -- cgit v1.2.3