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/SemaNamedCast.cpp b/lib/Sema/SemaNamedCast.cpp
index 3d3572d..06fc9d8 100644
--- a/lib/Sema/SemaNamedCast.cpp
+++ b/lib/Sema/SemaNamedCast.cpp
@@ -685,11 +685,10 @@
   if (DestPointee->isVoidType()) {
     assert(DestPointer && "Reference to void is not possible");
   } else if (DestRecord) {
-    if (!DestRecord->getDecl()->isDefinition()) {
-      Self.Diag(OpRange.getBegin(), diag::err_bad_dynamic_cast_incomplete)
-        << DestPointee.getUnqualifiedType() << DestRange;
+    if (Self.DiagnoseIncompleteType(OpRange.getBegin(), DestPointee, 
+                                    diag::err_bad_dynamic_cast_incomplete,
+                                    DestRange))
       return;
-    }
   } else {
     Self.Diag(OpRange.getBegin(), diag::err_bad_dynamic_cast_not_class)
       << DestPointee.getUnqualifiedType() << DestRange;
@@ -720,11 +719,10 @@
 
   const RecordType *SrcRecord = SrcPointee->getAsRecordType();
   if (SrcRecord) {
-    if (!SrcRecord->getDecl()->isDefinition()) {
-      Self.Diag(OpRange.getBegin(), diag::err_bad_dynamic_cast_incomplete)
-        << SrcPointee.getUnqualifiedType() << SrcExpr->getSourceRange();
+    if (Self.DiagnoseIncompleteType(OpRange.getBegin(), SrcPointee,
+                                    diag::err_bad_dynamic_cast_incomplete,
+                                    SrcExpr->getSourceRange()))
       return;
-    }
   } else {
     Self.Diag(OpRange.getBegin(), diag::err_bad_dynamic_cast_not_class)
       << SrcPointee.getUnqualifiedType() << SrcExpr->getSourceRange();