]> granicus.if.org Git - clang/commitdiff
Add a new failure kind, FK_Incomplete, to InitializationSequence, to
authorDouglas Gregor <dgregor@apple.com>
Thu, 20 May 2010 22:12:02 +0000 (22:12 +0000)
committerDouglas Gregor <dgregor@apple.com>
Thu, 20 May 2010 22:12:02 +0000 (22:12 +0000)
capture failures when we try to initialize an incomplete
type. Previously, we would (ab)use FK_ConversionFailed, then
occasionally dereference a null pointer when trying to diagnose the
failure. Fixes <rdar://problem/7959007>.

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

include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaDeclCXX.cpp
lib/Sema/SemaInit.cpp
lib/Sema/SemaInit.h

index 4d4ad714795ae59f17d7a68200fb205b394d5b05..bfcf13038d7edc2b7543590613411ce8e550c40f 100644 (file)
@@ -713,6 +713,7 @@ def note_uninit_reference_member : Note<
   "uninitialized reference member is here">;
 def warn_field_is_uninit : Warning<"field is uninitialized when used here">,
   InGroup<DiagGroup<"uninitialized">>;
+def err_init_incomplete_type : Error<"initialization of incomplete type %0">;
 
 def err_temp_copy_no_viable : Error<
   "no viable constructor %select{copying variable|copying parameter|"
index b32055a8a44ca8befc00f1d295a17dd26f050fd0..bd205267960b6e9bdbf0a543734b5dd6023d8d38 100644 (file)
@@ -1562,6 +1562,9 @@ BuildImplicitMemberInitializer(Sema &SemaRef, CXXConstructorDecl *Constructor,
                                ImplicitInitializerKind ImplicitInitKind,
                                FieldDecl *Field,
                                CXXBaseOrMemberInitializer *&CXXMemberInit) {
+  if (Field->isInvalidDecl())
+    return true;
+
   if (ImplicitInitKind == IIK_Copy) {
     SourceLocation Loc = Constructor->getLocation();
     ParmVarDecl *Param = Constructor->getParamDecl(0);
index c6a8b3595a42f497f73d847e77ca0d8920220cda..20f0c79c48c6d336c315b7a477e29de224e1bb5c 100644 (file)
@@ -2054,6 +2054,7 @@ bool InitializationSequence::isAmbiguous() const {
   case FK_ReferenceBindingToInitList:
   case FK_InitListBadDestinationType:
   case FK_DefaultInitOfConst:
+  case FK_Incomplete:
     return false;
     
   case FK_ReferenceInitOverloadFailed:
@@ -2649,7 +2650,7 @@ static void TryConstructorInitialization(Sema &S,
 
   // The type we're constructing needs to be complete.
   if (S.RequireCompleteType(Kind.getLocation(), DestType, 0)) {
-    Sequence.SetFailed(InitializationSequence::FK_ConversionFailed);
+    Sequence.SetFailed(InitializationSequence::FK_Incomplete);
     return;
   }
   
@@ -4137,6 +4138,11 @@ bool InitializationSequence::Diagnose(Sema &S,
         << DestType << (bool)DestType->getAs<RecordType>();
     }
     break;
+      
+    case FK_Incomplete:
+      S.RequireCompleteType(Kind.getLocation(), DestType, 
+                            diag::err_init_incomplete_type);
+      break;      
   }
   
   PrintInitLocationNote(S, Entity);
@@ -4215,6 +4221,10 @@ void InitializationSequence::dump(llvm::raw_ostream &OS) const {
     case FK_DefaultInitOfConst:
       OS << "default initialization of a const variable";
       break;
+        
+    case FK_Incomplete:
+      OS << "initialization of incomplete type";
+      break;
     }   
     OS << '\n';
     return;
index 35adf9e49ee08b7e7616e9bb96dbce35645f4424..a9064ede6d3422b418c9408e2dd859fd2774e2cf 100644 (file)
@@ -544,7 +544,9 @@ public:
     /// \brief Overloaded for initialization by constructor failed.
     FK_ConstructorOverloadFailed,
     /// \brief Default-initialization of a 'const' object.
-    FK_DefaultInitOfConst
+    FK_DefaultInitOfConst,
+    /// \brief Initialization of an incomplete type.
+    FK_Incomplete
   };
   
 private: