]> granicus.if.org Git - clang/commitdiff
modern objective-c transltion: Fixes a translation bug
authorFariborz Jahanian <fjahanian@apple.com>
Thu, 26 Apr 2012 23:20:25 +0000 (23:20 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Thu, 26 Apr 2012 23:20:25 +0000 (23:20 +0000)
of writing a __block variable being initialized with
a constructed object. // rdar://11326988

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

lib/Rewrite/RewriteModernObjC.cpp
test/Rewriter/rewrite-modern-block.mm

index 705a046223030ccf61e1cb058c0654cb28a9c022..041bd60aa35700f52a7a48898fe7ddcbd65af262 100644 (file)
@@ -4814,8 +4814,13 @@ void RewriteModernObjC::RewriteByRefVar(VarDecl *ND, bool firstDecl,
   bool hasInit = (ND->getInit() != 0);
   // FIXME. rewriter does not support __block c++ objects which
   // require construction.
-  if (hasInit && dyn_cast<CXXConstructExpr>(ND->getInit()))
-    hasInit = false;
+  if (hasInit)
+    if (CXXConstructExpr *CExp = dyn_cast<CXXConstructExpr>(ND->getInit())) {
+      CXXConstructorDecl *CXXDecl = CExp->getConstructor();
+      if (CXXDecl && CXXDecl->isDefaultConstructor())
+        hasInit = false;
+    }
+  
   unsigned flags = 0;
   if (HasCopyAndDispose)
     flags |= BLOCK_HAS_COPY_DISPOSE;
index f446c9c207d009dab4db0734794ad0c3e04fc468..675d206c2c7ff3e63ce11175dae6677ea29a26f9 100644 (file)
@@ -46,3 +46,19 @@ int  rdar7547630(const char *keybuf, const char *valuebuf) {
   return BI2;
 }
 
+// rdar://11326988
+typedef struct _z {
+    int location;
+    int length;
+} z;
+
+z w(int loc, int len);
+
+@interface rdar11326988
+@end
+@implementation rdar11326988 
+- (void)y:(int)options {
+    __attribute__((__blocks__(byref))) z firstRange = w(1, 0);
+    options &= ~(1 | 2);
+}
+@end