]> granicus.if.org Git - clang/commitdiff
diagnose declaring class extension after its implementation
authorFariborz Jahanian <fjahanian@apple.com>
Fri, 2 Apr 2010 20:53:05 +0000 (20:53 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Fri, 2 Apr 2010 20:53:05 +0000 (20:53 +0000)
(radar 7822210).

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@100226 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaDeclObjC.cpp
test/SemaObjC/class-extension-after-implementation.m [new file with mode: 0644]

index be00972dac5c13ad5b13c83df4d60a34e02a02a6..b66d6cc6e5a357c7b4dfe15552615a83125a315d 100644 (file)
@@ -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">;
index 9bc0846901aa7cf3f2705eb9a87bd3788372b1c5..0c47e63d99ebdbaa1dfa4e0405cb42511d4aff9c 100644 (file)
@@ -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 (file)
index 0000000..2d8a5b1
--- /dev/null
@@ -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
+