From: Fariborz Jahanian Date: Fri, 5 Jul 2013 17:18:11 +0000 (+0000) Subject: Objective-C: diagnose when synthesizing an ivar of X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8540b6e778545008fd521b002929b89ce10506ce;p=clang Objective-C: diagnose when synthesizing an ivar of abstract class type. // rdar://14261999 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@185710 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index 6b8ac2aee1..6574518044 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -911,7 +911,8 @@ def err_invalid_base_in_interface : Error< "%select{'struct|non-public 'interface|'class}0 %1'">; def err_abstract_type_in_decl : Error< - "%select{return|parameter|variable|field|instance variable}0 type %1 is an abstract class">; + "%select{return|parameter|variable|field|instance variable|" + "synthesized instance variable}0 type %1 is an abstract class">; def err_allocation_of_abstract_type : Error< "allocating an object of abstract class type %0">; def err_throw_abstract_type : Error< diff --git a/include/clang/Sema/Sema.h b/include/clang/Sema/Sema.h index 9c8c1c71c0..08c8ade33b 100644 --- a/include/clang/Sema/Sema.h +++ b/include/clang/Sema/Sema.h @@ -4835,6 +4835,7 @@ public: AbstractVariableType, AbstractFieldType, AbstractIvarType, + AbstractSynthesizedIvarType, AbstractArrayType }; diff --git a/lib/Sema/SemaObjCProperty.cpp b/lib/Sema/SemaObjCProperty.cpp index 7b8aba957d..ff5f7a5892 100644 --- a/lib/Sema/SemaObjCProperty.cpp +++ b/lib/Sema/SemaObjCProperty.cpp @@ -1082,8 +1082,14 @@ Decl *Sema::ActOnPropertyImplDecl(Scope *S, PropertyIvarType, /*Dinfo=*/0, ObjCIvarDecl::Private, (Expr *)0, true); - if (CompleteTypeErr) + if (RequireNonAbstractType(PropertyIvarLoc, + PropertyIvarType, + diag::err_abstract_type_in_decl, + AbstractSynthesizedIvarType)) { + Diag(property->getLocation(), diag::note_property_declare); Ivar->setInvalidDecl(); + } else if (CompleteTypeErr) + Ivar->setInvalidDecl(); ClassImpDecl->addDecl(Ivar); IDecl->makeDeclVisibleInContext(Ivar); diff --git a/test/SemaObjCXX/abstract-class-type-ivar.mm b/test/SemaObjCXX/abstract-class-type-ivar.mm index 990ba1c2ab..35787e655f 100644 --- a/test/SemaObjCXX/abstract-class-type-ivar.mm +++ b/test/SemaObjCXX/abstract-class-type-ivar.mm @@ -1,5 +1,6 @@ // RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s // rdar://12095239 +// rdar://14261999 class CppAbstractBase { public: @@ -16,11 +17,14 @@ class CppConcreteSub : public CppAbstractBase { CppConcreteSub _concrete; // expected-error{{instance variable type 'CppConcreteSub' is an abstract class}} } - (CppAbstractBase*)abstract; +@property (nonatomic, readonly) const CppConcreteSub& Prop; // expected-note {{property declared here}} @end + @implementation Objc - (CppAbstractBase*)abstract { return &_concrete; } +@synthesize Prop; // expected-error {{synthesized instance variable type 'const CppConcreteSub' is an abstract class}} @end class Cpp {