]> granicus.if.org Git - clang/commitdiff
When we determine that an initialization sequence failed due to an
authorDouglas Gregor <dgregor@apple.com>
Tue, 10 Apr 2012 20:43:46 +0000 (20:43 +0000)
committerDouglas Gregor <dgregor@apple.com>
Tue, 10 Apr 2012 20:43:46 +0000 (20:43 +0000)
incomplete type, keep track of the actual type that was
incomplete. Otherwise, we might fail to produce a diagnostic. Fixes
PR12498.

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

include/clang/Sema/Initialization.h
lib/Sema/SemaInit.cpp
test/SemaCXX/cxx0x-initializer-constructor.cpp

index 23cc4455dbc21fb82cbc4e2381ef293276daec43..4433843ff861f0b666e6cefba92d1b00ccc3c8f9 100644 (file)
@@ -734,6 +734,9 @@ private:
   /// \brief The candidate set created when initialization failed.
   OverloadCandidateSet FailedCandidateSet;
 
+  /// \brief The incomplete type that caused a failure.
+  QualType FailedIncompleteType;
+  
   /// \brief Prints a follow-up note that highlights the location of
   /// the initialized entity, if it's remote.
   void PrintInitLocationNote(Sema &S, const InitializedEntity &Entity);
@@ -949,6 +952,8 @@ public:
   void SetFailed(FailureKind Failure) {
     SequenceKind = FailedSequence;
     this->Failure = Failure;
+    assert((Failure != FK_Incomplete || !FailedIncompleteType.isNull()) &&
+           "Incomplete type failure requires a type!");
   }
   
   /// \brief Note that this initialization sequence failed due to failed
@@ -967,6 +972,13 @@ public:
     return FailedOverloadResult;
   }
 
+  /// \brief Note that this initialization sequence failed due to an
+  /// incomplete type.
+  void setIncompleteTypeFailure(QualType IncompleteType) {
+    FailedIncompleteType = IncompleteType;
+    SetFailed(FK_Incomplete);
+  }
+
   /// \brief Determine why initialization failed.
   FailureKind getFailureKind() const {
     assert(Failed() && "Not an initialization failure!");
index ee051428da8ee187fec95e90bcc521b9f8ce5c06..a65b41fd1cb676b08e8b15e1b19342e4ed15a479 100644 (file)
@@ -2877,7 +2877,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_Incomplete);
+    Sequence.setIncompleteTypeFailure(DestType);
     return;
   }
 
@@ -3109,7 +3109,7 @@ static void TryListInitialization(Sema &S,
   }
   if (DestType->isRecordType()) {
     if (S.RequireCompleteType(InitList->getLocStart(), DestType, S.PDiag())) {
-      Sequence.SetFailed(InitializationSequence::FK_Incomplete);
+      Sequence.setIncompleteTypeFailure(DestType);
       return;
     }
 
@@ -5687,7 +5687,7 @@ bool InitializationSequence::Diagnose(Sema &S,
     break;
 
   case FK_Incomplete:
-    S.RequireCompleteType(Kind.getLocation(), DestType,
+    S.RequireCompleteType(Kind.getLocation(), FailedIncompleteType,
                           diag::err_init_incomplete_type);
     break;
 
index 68c149218a738567c9b9a701657152c04022199e..09aca24b704bdca5b343bdc717db5f611d93ba47 100644 (file)
@@ -267,3 +267,17 @@ namespace PR12120 {
   struct B { explicit B(short); B(long); }; // expected-note 2 {{candidate}}
   B b = { 0 }; // expected-error {{ambiguous}}
 }
+
+namespace PR12498 {
+  class ArrayRef; // expected-note{{forward declaration}}
+
+  struct C {
+    void foo(const ArrayRef&); // expected-note{{passing argument to parameter here}}
+  };
+
+  static void bar(C* c)
+  {
+    c->foo({ nullptr, 1 }); // expected-error{{initialization of incomplete type 'const PR12498::ArrayRef'}}
+  }
+
+}