Centralize error reporting of improper uses of incomplete types in the
new DiagnoseIncompleteType. It provides additional information about
struct/class/union/enum types when possible, either by pointing to the
forward declaration of that type or by pointing to the definition (if
we're in the process of defining that type). 
Fixes <rdar://problem/6500531>.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@62521 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp
index 33a31c7..95f9200 100644
--- a/lib/Sema/SemaDeclCXX.cpp
+++ b/lib/Sema/SemaDeclCXX.cpp
@@ -339,8 +339,9 @@
   // C++ [class.derived]p2:
   //   The class-name in a base-specifier shall not be an incompletely
   //   defined class.
-  if (BaseType->isIncompleteType())
-    return Diag(BaseLoc, diag::err_incomplete_base_class) << SpecifierRange;
+  if (DiagnoseIncompleteType(BaseLoc, BaseType, diag::err_incomplete_base_class,
+                             SpecifierRange))
+    return true;
 
   // If the base class is polymorphic, the new one is, too.
   RecordDecl *BaseDecl = BaseType->getAsRecordType()->getDecl();
@@ -2179,17 +2180,19 @@
   // incomplete type, other than [cv] void*.
   QualType BaseType = ExDeclType;
   int Mode = 0; // 0 for direct type, 1 for pointer, 2 for reference
+  unsigned DK = diag::err_catch_incomplete;
   if (const PointerType *Ptr = BaseType->getAsPointerType()) {
     BaseType = Ptr->getPointeeType();
     Mode = 1;
+    DK = diag::err_catch_incomplete_ptr;
   } else if(const ReferenceType *Ref = BaseType->getAsReferenceType()) {
     BaseType = Ref->getPointeeType();
     Mode = 2;
+    DK = diag::err_catch_incomplete_ref;
   }
-  if ((Mode == 0 || !BaseType->isVoidType()) && BaseType->isIncompleteType()) {
+  if ((Mode == 0 || !BaseType->isVoidType()) && 
+      DiagnoseIncompleteType(Begin, BaseType, DK))
     Invalid = true;
-    Diag(Begin, diag::err_catch_incomplete) << BaseType << Mode;
-  }
 
   // FIXME: Need to test for ability to copy-construct and destroy the
   // exception variable.