]> granicus.if.org Git - clang/commitdiff
[Parser][ObjC] Make sure c++11 in-class initialization is done when the
authorAkira Hatanaka <ahatanaka@apple.com>
Mon, 18 Apr 2016 18:19:45 +0000 (18:19 +0000)
committerAkira Hatanaka <ahatanaka@apple.com>
Mon, 18 Apr 2016 18:19:45 +0000 (18:19 +0000)
constructor's definition is in an implementation block.

Without this commit, ptr doesn't get initialized to null in the
following code:

struct S {
  S();
  void *ptr = nullptr;
};

@implementation I
  S::S() {}
@end

rdar://problem/25693624

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

lib/Parse/ParseObjc.cpp
test/Parser/objc-default-ctor-init.mm [new file with mode: 0644]

index 708e2a7edc118d9f65aad1126cb2ff27ca683fce..4b4494d27bee3dfee83224e5ecde9fa5bc461d75 100644 (file)
@@ -3651,6 +3651,8 @@ void Parser::ParseLexedObjCMethodDefs(LexedMethod &LM, bool parseMethod) {
   else {
     if (Tok.is(tok::colon))
       ParseConstructorInitializer(MCDecl);
+    else
+      Actions.ActOnDefaultCtorInitializers(MCDecl);
     ParseFunctionStatementBody(MCDecl, BodyScope);
   }
   
diff --git a/test/Parser/objc-default-ctor-init.mm b/test/Parser/objc-default-ctor-init.mm
new file mode 100644 (file)
index 0000000..fda8bef
--- /dev/null
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 -triple x86_64-apple-macosx10.10 -std=c++11 -ast-dump %s | FileCheck %s
+// CHECK: CXXCtorInitializer Field {{.*}} 'ptr' 'void *'
+
+@interface NSObject
+@end
+
+@interface I : NSObject
+@end
+
+struct S {
+  S();
+  void *ptr = nullptr;
+};
+
+@implementation I
+S::S() {}
+@end