diff options
-rw-r--r-- | include/clang/Basic/DiagnosticSemaKinds.td | 2 | ||||
-rw-r--r-- | include/clang/Sema/Sema.h | 2 | ||||
-rw-r--r-- | lib/Sema/SemaExprObjC.cpp | 8 | ||||
-rw-r--r-- | test/SemaObjC/exprs.m | 10 |
4 files changed, 20 insertions, 2 deletions
diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index ea1ef56010..b40aa61ba5 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -2869,6 +2869,8 @@ def err_objc_pointer_cxx_catch_fragile : Error< "exception model">; def err_objc_object_catch : Error< "can't catch an Objective C object by value">; +def err_incomplete_type_objc_at_encode : Error< + "'@encode' of incomplete type %0">; def warn_setter_getter_impl_required : Warning< "property %0 requires method %1 to be defined - " diff --git a/include/clang/Sema/Sema.h b/include/clang/Sema/Sema.h index 6265c67c07..d1487cc317 100644 --- a/include/clang/Sema/Sema.h +++ b/include/clang/Sema/Sema.h @@ -3105,7 +3105,7 @@ public: Expr **Strings, unsigned NumStrings); - Expr *BuildObjCEncodeExpression(SourceLocation AtLoc, + ExprResult BuildObjCEncodeExpression(SourceLocation AtLoc, TypeSourceInfo *EncodedTypeInfo, SourceLocation RParenLoc); ExprResult BuildCXXMemberCallExpr(Expr *Exp, NamedDecl *FoundDecl, diff --git a/lib/Sema/SemaExprObjC.cpp b/lib/Sema/SemaExprObjC.cpp index 2a262f0939..3444cb5a49 100644 --- a/lib/Sema/SemaExprObjC.cpp +++ b/lib/Sema/SemaExprObjC.cpp @@ -119,7 +119,7 @@ ExprResult Sema::ParseObjCStringLiteral(SourceLocation *AtLocs, return new (Context) ObjCStringLiteral(S, Ty, AtLocs[0]); } -Expr *Sema::BuildObjCEncodeExpression(SourceLocation AtLoc, +ExprResult Sema::BuildObjCEncodeExpression(SourceLocation AtLoc, TypeSourceInfo *EncodedTypeInfo, SourceLocation RParenLoc) { QualType EncodedType = EncodedTypeInfo->getType(); @@ -127,6 +127,12 @@ Expr *Sema::BuildObjCEncodeExpression(SourceLocation AtLoc, if (EncodedType->isDependentType()) StrTy = Context.DependentTy; else { + if (!EncodedType->getAsArrayTypeUnsafe()) // Incomplete array is handled. + if (RequireCompleteType(AtLoc, EncodedType, + PDiag(diag::err_incomplete_type_objc_at_encode) + << EncodedTypeInfo->getTypeLoc().getSourceRange())) + return ExprError(); + std::string Str; Context.getObjCEncodingForType(EncodedType, Str); diff --git a/test/SemaObjC/exprs.m b/test/SemaObjC/exprs.m index d7c122356f..2b505e0eae 100644 --- a/test/SemaObjC/exprs.m +++ b/test/SemaObjC/exprs.m @@ -32,3 +32,13 @@ void test3(Object *o) { // this is ok. __sync_bool_compare_and_swap(&g, 0, o); } + +@class Incomplete_ObjC_class; +struct Incomplete_struct; // expected-note {{forward declaration}} + +void test_encode() { + (void)@encode(Incomplete_ObjC_class); // expected-error {{incomplete type}} + (void)@encode(struct Incomplete_struct); // expected-error {{incomplete type}} + (void)@encode(Incomplete_ObjC_class*); + (void)@encode(id); +} |