]> granicus.if.org Git - clang/commitdiff
Add documentation about boxing enum types and a codegen test to make
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Tue, 15 May 2012 20:45:35 +0000 (20:45 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Tue, 15 May 2012 20:45:35 +0000 (20:45 +0000)
sure we pick up the underlying type, per suggestion by Fariborz.

No functionality change.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@156851 91177308-0d34-0410-b5e6-96231b3b80d8

docs/ObjectiveCLiterals.html
test/CodeGenObjC/boxing.m

index ca7704d0a25bea70ed3e5aae3d03419d557623e0..33f73e4a5b916ac06f0eefea68adab74f0bb0a1c 100644 (file)
@@ -157,6 +157,18 @@ NSNumber *red = @(Red), *green = @(Green), *blue = @(Blue); // => [NSNumber numb
 then the fixed underlying type will be used to select the correct <code>NSNumber</code> creation method.
 </p>
 
+<p>
+Boxing a value of enum type will result in a <code>NSNumber</code> pointer with a creation method according to the underlying type of the enum,
+which can be a <a href="http://clang.llvm.org/docs/LanguageExtensions.html#objc_fixed_enum">fixed underlying type</a> or a compiler-defined
+integer type capable of representing the values of all the members of the enumeration:
+</p>
+
+<pre>
+typedef enum : unsigned char { Red, Green, Blue } Color;
+Color col = Red;
+NSNumber *nsCol = @(col); // => [NSNumber numberWithUnsignedChar:]
+</pre>
+
 <h3>Boxed C Strings</h3>
 
 <p>
index 3c24779f9a1e4526a949684d2fbc1f0d33183ebc..9664298154dc69a6eec17d10d5b03b92bc198650 100644 (file)
@@ -85,4 +85,11 @@ int main() {
   @((NSUInteger)i);
   // CHECK: load i8** [[stringWithUTF8StringSEL]]
   const char *s; @(s);
+
+  typedef enum : NSInteger { Red, Green, Blue } Color;
+  // CHECK: load i8** [[WithIntegerSEL]]
+  @(Red);
+  Color col = Red;
+  // CHECK: load i8** [[WithIntegerSEL]]
+  @(col);
 }