[PATCH] PR11410 - Confusing diagnostic when trailing array element tries to call deleted default constructor
Nikola Smiljanić
popizdeh at gmail.com
Sun May 25 20:28:09 PDT 2014
Added test.
http://reviews.llvm.org/D3739
Files:
include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaInit.cpp
test/SemaCXX/cxx0x-initializer-constructor.cpp
Index: include/clang/Basic/DiagnosticSemaKinds.td
===================================================================
--- include/clang/Basic/DiagnosticSemaKinds.td
+++ include/clang/Basic/DiagnosticSemaKinds.td
@@ -1486,6 +1486,9 @@
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: lib/Sema/SemaInit.cpp
===================================================================
--- lib/Sema/SemaInit.cpp
+++ lib/Sema/SemaInit.cpp
@@ -429,9 +429,6 @@
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 @@
} 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 @@
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: test/SemaCXX/cxx0x-initializer-constructor.cpp
===================================================================
--- test/SemaCXX/cxx0x-initializer-constructor.cpp
+++ test/SemaCXX/cxx0x-initializer-constructor.cpp
@@ -375,3 +375,14 @@
};
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}}
+}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D3739.9794.patch
Type: text/x-patch
Size: 2613 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140526/dfb01361/attachment.bin>
More information about the cfe-commits
mailing list