diff options
author | Alex Lorenz <arphaman@gmail.com> | 2017-11-08 21:33:15 +0000 |
---|---|---|
committer | Alex Lorenz <arphaman@gmail.com> | 2017-11-08 21:33:15 +0000 |
commit | 49370ac7e2eae1e81e073ea20572df87ac614d16 (patch) | |
tree | d79cb09e658c67b4f24245c314b158f6485d6403 /clang/lib/Sema/SemaExprObjC.cpp | |
parent | 7adb2fdbbadd0c588a2137c7362a9099574d79ae (diff) | |
download | bcm5719-llvm-49370ac7e2eae1e81e073ea20572df87ac614d16.tar.gz bcm5719-llvm-49370ac7e2eae1e81e073ea20572df87ac614d16.zip |
[ObjC] Boxed strings should use the nullability from stringWithUTF8String's return type
Objective-C NSString has a class method stringWithUTF8String that creates a new
NSString from a C string. Objective-C box expression @(...) can be used to
create an NSString instead of invoking the stringWithUTF8String method directly
(The compiler lowers it down to the invocation though). This commit ensures that
the type of @(string-value) gets the same nullability attributes as the return
type of stringWithUTF8String to ensure that the diagnostics are consistent
between the two.
rdar://33847186
Differential Revision: https://reviews.llvm.org/D39762
llvm-svn: 317727
Diffstat (limited to 'clang/lib/Sema/SemaExprObjC.cpp')
-rw-r--r-- | clang/lib/Sema/SemaExprObjC.cpp | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/clang/lib/Sema/SemaExprObjC.cpp b/clang/lib/Sema/SemaExprObjC.cpp index 369ba64cd97..6ed5047c35d 100644 --- a/clang/lib/Sema/SemaExprObjC.cpp +++ b/clang/lib/Sema/SemaExprObjC.cpp @@ -564,6 +564,13 @@ ExprResult Sema::BuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) { BoxingMethod = StringWithUTF8StringMethod; BoxedType = NSStringPointer; + // Transfer the nullability from method's return type. + Optional<NullabilityKind> Nullability = + BoxingMethod->getReturnType()->getNullability(Context); + if (Nullability) + BoxedType = Context.getAttributedType( + AttributedType::getNullabilityAttrKind(*Nullability), BoxedType, + BoxedType); } } else if (ValueType->isBuiltinType()) { // The other types we support are numeric, char and BOOL/bool. We could also |