From: Akira Hatanaka Date: Mon, 18 Apr 2016 18:19:45 +0000 (+0000) Subject: [Parser][ObjC] Make sure c++11 in-class initialization is done when the X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3ae2ef0f0bbfcb5829ac2ac4f63ac555d94e3f78;p=clang [Parser][ObjC] Make sure c++11 in-class initialization is done when the 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 --- diff --git a/lib/Parse/ParseObjc.cpp b/lib/Parse/ParseObjc.cpp index 708e2a7edc..4b4494d27b 100644 --- a/lib/Parse/ParseObjc.cpp +++ b/lib/Parse/ParseObjc.cpp @@ -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 index 0000000000..fda8befa37 --- /dev/null +++ b/test/Parser/objc-default-ctor-init.mm @@ -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