aboutsummaryrefslogtreecommitdiffhomepage
path: root/objectivec/GPBBootstrap.h
diff options
context:
space:
mode:
authorGravatar Thomas Van Lenten <thomasvl@google.com>2015-09-30 13:34:16 -0400
committerGravatar Thomas Van Lenten <thomasvl@google.com>2015-10-01 09:03:30 -0400
commitad2d5c926bab7af19fa43688b86d368575fd90ce (patch)
treef726631848bd82d528408dc727e1e8ac46419b16 /objectivec/GPBBootstrap.h
parentebf3eb630de34105432fb998492346929b577dcb (diff)
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.
Diffstat (limited to 'objectivec/GPBBootstrap.h')
-rw-r--r--objectivec/GPBBootstrap.h20
1 files changed, 14 insertions, 6 deletions
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;