diff options
author | Brian Kelley <bkelley@microsoft.com> | 2017-03-29 17:31:42 +0000 |
---|---|---|
committer | Brian Kelley <bkelley@microsoft.com> | 2017-03-29 17:31:42 +0000 |
commit | b18f3efe980fabecca8feac4bd1512e4e9c33d57 (patch) | |
tree | b00a986834fb1c85e4482440862b8ca38c8d1fb6 /lib/Sema/SemaDeclCXX.cpp | |
parent | 1895a41dddbc05cdcfeb06ab7cb8f3e73679b30b (diff) |
[Objective-C] C++ Classes with __weak Members non-POD Types when using -fobjc-weak
Summary: When adding an Objective-C retainable type member to a C++ class, also check the LangOpts.ObjCWeak flag and the lifetime qualifier so __weak qualified Objective-C pointer members cause the class to be a non-POD type with non-trivial special members, so the compiler always emits the necessary runtime calls for copying, moving, and destroying the weak member. Otherwise, Objective-C++ classes with weak Objective-C pointer members compiled with -fobjc-weak exhibit undefined behavior if the C++ class is classified as a POD type.
Reviewers: rsmith, benlangmuir, doug.gregor, rjmccall
Reviewed By: rjmccall
Subscribers: cfe-commits
Differential Revision: https://reviews.llvm.org/D31003
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@299008 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaDeclCXX.cpp')
-rw-r--r-- | lib/Sema/SemaDeclCXX.cpp | 7 |
1 files changed, 2 insertions, 5 deletions
diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index 9500e6d3e6..c369d62ad8 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -4399,11 +4399,8 @@ BuildImplicitMemberInitializer(Sema &SemaRef, CXXConstructorDecl *Constructor, } } - if (SemaRef.getLangOpts().ObjCAutoRefCount && - FieldBaseElementType->isObjCRetainableType() && - FieldBaseElementType.getObjCLifetime() != Qualifiers::OCL_None && - FieldBaseElementType.getObjCLifetime() != Qualifiers::OCL_ExplicitNone) { - // ARC: + if (FieldBaseElementType.hasNonTrivialObjCLifetime()) { + // ARC and Weak: // Default-initialize Objective-C pointers to NULL. CXXMemberInit = new (SemaRef.Context) CXXCtorInitializer(SemaRef.Context, Field, |