From 3684bd4c9518f6507d375ff8e4a4e32ce3bb51c3 Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Mon, 2 Nov 2009 18:45:36 +0000 Subject: [PATCH] Diagnose implementation of a property declared in a category in its class implementation instead of crashing. Fixes radar 7350345. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@85813 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/DiagnosticSemaKinds.td | 5 +++++ lib/Sema/SemaDeclObjC.cpp | 8 ++++++++ test/SemaObjC/property-category-4.m | 18 ++++++++++++++++++ 3 files changed, 31 insertions(+) create mode 100644 test/SemaObjC/property-category-4.m diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index 00723a3af9..8c7c0cbbe9 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -271,6 +271,11 @@ def error_missing_property_context : Error< "missing context for property implementation declaration">; def error_bad_property_decl : Error< "property implementation must have its declaration in interface %0">; +def error_category_property : Error< + "property declared in category %0 cannot be implemented in " + "class implementation">; +def note_category_property : Note< + "property declared here">; def error_synthesize_category_decl : Error< "@synthesize not allowed in a category's implementation">; def error_missing_property_interface : Error< diff --git a/lib/Sema/SemaDeclObjC.cpp b/lib/Sema/SemaDeclObjC.cpp index d1b68a7977..881652f7aa 100644 --- a/lib/Sema/SemaDeclObjC.cpp +++ b/lib/Sema/SemaDeclObjC.cpp @@ -2047,6 +2047,14 @@ Sema::DeclPtrTy Sema::ActOnPropertyImplDecl(SourceLocation AtLoc, Diag(PropertyLoc, diag::error_bad_property_decl) << IDecl->getDeclName(); return DeclPtrTy(); } + if (const ObjCCategoryDecl *CD = + dyn_cast(property->getDeclContext())) { + if (CD->getIdentifier()) { + Diag(PropertyLoc, diag::error_category_property) << CD->getDeclName(); + Diag(property->getLocation(), diag::note_category_property); + return DeclPtrTy(); + } + } } else if ((CatImplClass = dyn_cast(ClassImpDecl))) { if (Synthesize) { Diag(AtLoc, diag::error_synthesize_category_decl); diff --git a/test/SemaObjC/property-category-4.m b/test/SemaObjC/property-category-4.m new file mode 100644 index 0000000000..ee08b09c01 --- /dev/null +++ b/test/SemaObjC/property-category-4.m @@ -0,0 +1,18 @@ +// RUN: clang-cc -fsyntax-only -verify %s + +@interface IDELogNavigator +{ + id selectedObjects; +} +@end + +@interface IDELogNavigator (CAT) + @property (readwrite, retain) id selectedObjects; // expected-note {{property declared here}} + @property (readwrite, retain) id d_selectedObjects; // expected-note {{property declared here}} +@end + +@implementation IDELogNavigator +@synthesize selectedObjects = _selectedObjects; // expected-error {{property declared in category 'CAT' cannot be implemented in class implementation}} +@dynamic d_selectedObjects; // expected-error {{property declared in category 'CAT' cannot be implemented in class implementation}} +@end + -- 2.40.0