From 24e14089cc509ff48cf7f1e6f4f9070803dd739b Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Fri, 2 Apr 2010 20:53:05 +0000 Subject: [PATCH] diagnose declaring class extension after its implementation (radar 7822210). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@100226 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/DiagnosticSemaKinds.td | 4 ++++ lib/Sema/SemaDeclObjC.cpp | 5 +++++ test/SemaObjC/class-extension-after-implementation.m | 11 +++++++++++ 3 files changed, 20 insertions(+) create mode 100644 test/SemaObjC/class-extension-after-implementation.m diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index be00972dac..b66d6cc6e5 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -256,6 +256,10 @@ def warn_property_attribute : Warning< def warn_property_types_are_incompatible : Warning< "property type %0 is incompatible with type %1 inherited from %2">; def err_undef_interface : Error<"cannot find interface declaration for %0">; +def err_class_extension_after_impl : Error< + "cannot declare class extension for %0 after class implementation">; +def note_implementation_declared : Note< + "class implementation is declared here">; def warn_dup_category_def : Warning< "duplicate definition of category %1 on interface %0">; def err_conflicting_super_class : Error<"conflicting super class name %0">; diff --git a/lib/Sema/SemaDeclObjC.cpp b/lib/Sema/SemaDeclObjC.cpp index 9bc0846901..0c47e63d99 100644 --- a/lib/Sema/SemaDeclObjC.cpp +++ b/lib/Sema/SemaDeclObjC.cpp @@ -431,6 +431,11 @@ ActOnStartCategoryInterface(SourceLocation AtInterfaceLoc, // Class extensions require a special treatment. Use an existing one. // Note that 'getClassExtension()' can return NULL. CDecl = IDecl->getClassExtension(); + if (IDecl->getImplementation()) { + Diag(ClassLoc, diag::err_class_extension_after_impl) << ClassName; + Diag(IDecl->getImplementation()->getLocation(), + diag::note_implementation_declared); + } } if (!CDecl) { diff --git a/test/SemaObjC/class-extension-after-implementation.m b/test/SemaObjC/class-extension-after-implementation.m new file mode 100644 index 0000000000..2d8a5b1d4d --- /dev/null +++ b/test/SemaObjC/class-extension-after-implementation.m @@ -0,0 +1,11 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s +// rdar://7822210 + +@interface A @end + +@implementation A @end // expected-note {{class implementation is declared here}} + +@interface A () // expected-error {{cannot declare class extension for 'A' after class implementation}} +-(void) im0; +@end + -- 2.50.1