]> granicus.if.org Git - clang/commitdiff
PR11410 - Confusing diagnostic when trailing array element tries to call deleted...
authorNikola Smiljanic <popizdeh@gmail.com>
Fri, 30 May 2014 01:28:28 +0000 (01:28 +0000)
committerNikola Smiljanic <popizdeh@gmail.com>
Fri, 30 May 2014 01:28:28 +0000 (01:28 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@209869 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaInit.cpp
test/SemaCXX/cxx0x-initializer-constructor.cpp

index 209f4259b93fcb5b1c0eeadbd2c4bc0abc0391d5..758bf23c30d4905cb7b02532fb1be2e935a4c3ce 100644 (file)
@@ -1490,6 +1490,9 @@ def warn_uninit_byref_blockvar_captured_by_block : Warning<
   InGroup<Uninitialized>, DefaultIgnore;
 def note_block_var_fixit_add_initialization : Note<
   "maybe you meant to use __block %0">;
+def note_omitted_element_default_constructed : Note<
+  "initializer list shorter than initialized object, omitted element was "
+  "implicitly default constructed">;
 def note_var_fixit_add_initialization : Note<
   "initialize the variable %0 to silence this warning">;
 def note_uninit_fixit_remove_cond : Note<
index 9ef43cc81f64accd6777e79f9c7b7919a18a1fbd..0dd040faff026711417c9f510925b75f03b6c117 100644 (file)
@@ -429,9 +429,6 @@ InitListChecker::FillInValueInitializations(const InitializedEntity &Entity,
                                             bool &RequiresSecondPass) {
   assert((ILE->getType() != SemaRef.Context.VoidTy) &&
          "Should not have void type");
-  SourceLocation Loc = ILE->getLocStart();
-  if (ILE->getSyntacticForm())
-    Loc = ILE->getSyntacticForm()->getLocStart();
 
   if (const RecordType *RType = ILE->getType()->getAs<RecordType>()) {
     const RecordDecl *RDecl = RType->getDecl();
@@ -489,6 +486,9 @@ InitListChecker::FillInValueInitializations(const InitializedEntity &Entity,
   } else
     ElementType = ILE->getType();
 
+  SourceLocation Loc = ILE->getLocEnd();
+  if (ILE->getSyntacticForm())
+    Loc = ILE->getSyntacticForm()->getLocEnd();
 
   for (unsigned Init = 0; Init != NumElements; ++Init) {
     if (hadError)
@@ -505,6 +505,11 @@ InitListChecker::FillInValueInitializations(const InitializedEntity &Entity,
       InitializationSequence InitSeq(SemaRef, ElementEntity, Kind, None);
       if (!InitSeq) {
         InitSeq.Diagnose(SemaRef, ElementEntity, Kind, None);
+        if (NumInits < NumElements &&
+            InitSeq.getFailureKind() ==
+              InitializationSequence::FK_ConstructorOverloadFailed &&
+            InitSeq.getFailedOverloadResult() == OverloadingResult::OR_Deleted)
+          SemaRef.Diag(Loc, diag::note_omitted_element_default_constructed);
         hadError = true;
         return;
       }
index 75b2341f3b6e7ca99897a4486080f1188a62ffc2..47afead305cbf7142be94f68823913a102964694 100644 (file)
@@ -375,3 +375,14 @@ namespace PR19729 {
   };
   B *p = new ({123}) B;
 }
+
+namespace PR11410 {
+  struct A {
+    A() = delete; // expected-note {{deleted here}}
+    A(int);
+  };
+
+  A a[3] = {
+    {1}, {2}
+  }; // expected-error {{call to deleted constructor}} expected-note {{implicitly default constructed}}
+}