r266645 - [Parser][ObjC] Make sure c++11 in-class initialization is done when the

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 18 11:38:10 PDT 2016


On Mon, Apr 18, 2016 at 11:19 AM, Akira Hatanaka via cfe-commits <
cfe-commits at lists.llvm.org> wrote:

> Author: ahatanak
> Date: Mon Apr 18 13:19:45 2016
> New Revision: 266645
>
> URL: http://llvm.org/viewvc/llvm-project?rev=266645&view=rev
> Log:
> [Parser][ObjC] Make sure c++11 in-class initialization is done when the
> constructor's definition is in an implementation block.
>

This doesn't just fix the C++11 case, it also fixes this:

struct Q { Q(); };
struct S { S(); Q q;  };

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

We previously did not run the Q default constructor from the S default
constructor.

Can you also add that to the test, please?

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
>
> Added:
>     cfe/trunk/test/Parser/objc-default-ctor-init.mm
> Modified:
>     cfe/trunk/lib/Parse/ParseObjc.cpp
>
> Modified: cfe/trunk/lib/Parse/ParseObjc.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseObjc.cpp?rev=266645&r1=266644&r2=266645&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/Parse/ParseObjc.cpp (original)
> +++ cfe/trunk/lib/Parse/ParseObjc.cpp Mon Apr 18 13:19:45 2016
> @@ -3651,6 +3651,8 @@ void Parser::ParseLexedObjCMethodDefs(Le
>    else {
>      if (Tok.is(tok::colon))
>        ParseConstructorInitializer(MCDecl);
> +    else
> +      Actions.ActOnDefaultCtorInitializers(MCDecl);
>      ParseFunctionStatementBody(MCDecl, BodyScope);
>    }
>
>
> Added: cfe/trunk/test/Parser/objc-default-ctor-init.mm
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/objc-default-ctor-init.mm?rev=266645&view=auto
>
> ==============================================================================
> --- cfe/trunk/test/Parser/objc-default-ctor-init.mm (added)
> +++ cfe/trunk/test/Parser/objc-default-ctor-init.mm Mon Apr 18 13:19:45
> 2016
> @@ -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 *'
> +
> + at interface NSObject
> + at end
> +
> + at interface I : NSObject
> + at end
> +
> +struct S {
> +  S();
> +  void *ptr = nullptr;
> +};
> +
> + at implementation I
> +S::S() {}
> + at end
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160418/e1908d67/attachment-0001.html>


More information about the cfe-commits mailing list