[cfe-commits] r104286 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaDeclCXX.cpp lib/Sema/SemaInit.cpp lib/Sema/SemaInit.h

Douglas Gregor dgregor at apple.com
Thu May 20 15:12:02 PDT 2010


Author: dgregor
Date: Thu May 20 17:12:02 2010
New Revision: 104286

URL: http://llvm.org/viewvc/llvm-project?rev=104286&view=rev
Log:
Add a new failure kind, FK_Incomplete, to InitializationSequence, to
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>.

Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Sema/SemaDeclCXX.cpp
    cfe/trunk/lib/Sema/SemaInit.cpp
    cfe/trunk/lib/Sema/SemaInit.h

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=104286&r1=104285&r2=104286&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Thu May 20 17:12:02 2010
@@ -713,6 +713,7 @@
   "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|"

Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=104286&r1=104285&r2=104286&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Thu May 20 17:12:02 2010
@@ -1562,6 +1562,9 @@
                                ImplicitInitializerKind ImplicitInitKind,
                                FieldDecl *Field,
                                CXXBaseOrMemberInitializer *&CXXMemberInit) {
+  if (Field->isInvalidDecl())
+    return true;
+
   if (ImplicitInitKind == IIK_Copy) {
     SourceLocation Loc = Constructor->getLocation();
     ParmVarDecl *Param = Constructor->getParamDecl(0);

Modified: cfe/trunk/lib/Sema/SemaInit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=104286&r1=104285&r2=104286&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaInit.cpp (original)
+++ cfe/trunk/lib/Sema/SemaInit.cpp Thu May 20 17:12:02 2010
@@ -2054,6 +2054,7 @@
   case FK_ReferenceBindingToInitList:
   case FK_InitListBadDestinationType:
   case FK_DefaultInitOfConst:
+  case FK_Incomplete:
     return false;
     
   case FK_ReferenceInitOverloadFailed:
@@ -2649,7 +2650,7 @@
 
   // 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 @@
         << 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 @@
     case FK_DefaultInitOfConst:
       OS << "default initialization of a const variable";
       break;
+        
+    case FK_Incomplete:
+      OS << "initialization of incomplete type";
+      break;
     }   
     OS << '\n';
     return;

Modified: cfe/trunk/lib/Sema/SemaInit.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.h?rev=104286&r1=104285&r2=104286&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaInit.h (original)
+++ cfe/trunk/lib/Sema/SemaInit.h Thu May 20 17:12:02 2010
@@ -544,7 +544,9 @@
     /// \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:





More information about the cfe-commits mailing list