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
diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td
index be00972..b66d6cc 100644
--- a/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/include/clang/Basic/DiagnosticSemaKinds.td
@@ -256,6 +256,10 @@
 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 9bc0846..0c47e63 100644
--- a/lib/Sema/SemaDeclObjC.cpp
+++ b/lib/Sema/SemaDeclObjC.cpp
@@ -431,6 +431,11 @@
     // 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 0000000..2d8a5b1
--- /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
+