diff options
-rw-r--r-- | include/clang/Basic/DiagnosticSemaKinds.td | 4 | ||||
-rw-r--r-- | lib/Sema/SemaDeclObjC.cpp | 5 | ||||
-rw-r--r-- | test/SemaObjC/class-extension-after-implementation.m | 11 |
3 files changed, 20 insertions, 0 deletions
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 + |