[PATCH] [Patch] Fix for assertion when incomplete array type is used as template param
jyoti allur
jyoti.yalamanchili at gmail.com
Tue Oct 29 08:15:27 PDT 2013
Moved the check to SemaInit.cpp.
Function template specialization information is not yet set when initializer elements are being verified in InitializationSequence::InitializeFrom
So removed the 'note' about function template specialization.
Please let me know if this patch is okay ?
Hi dblaikie, rsmith,
http://llvm-reviews.chandlerc.com/D1700
CHANGE SINCE LAST DIFF
http://llvm-reviews.chandlerc.com/D1700?vs=4957&id=5230#toc
Files:
cxx0x-function-template-specialization.cpp
llvm/tools/clang/lib/Sema/SemaInit.cpp
llvm/tools/clang/include/clang/Sema/Initialization.h
Index: cxx0x-function-template-specialization.cpp
===================================================================
--- cxx0x-function-template-specialization.cpp
+++ cxx0x-function-template-specialization.cpp
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -std=c++0x -fsyntax-only -verify %s
+
+template<class T>
+T&& create();
+
+template<class T, class... Args>
+void test() {
+ T t(create<Args>()...); // expected-error {{definition of variable with array type needs an explicit size or an initializer}}
+ (void) t;
+}
+
+int main() {
+ test<int[]>(); // expected-note {{in instantiation of function template specialization 'test<int []>' requested here}}
+}
+
Index: llvm/tools/clang/lib/Sema/SemaInit.cpp
===================================================================
--- llvm/tools/clang/lib/Sema/SemaInit.cpp
+++ llvm/tools/clang/lib/Sema/SemaInit.cpp
@@ -2704,6 +2704,7 @@
case FK_VariableLengthArrayHasInitializer:
case FK_PlaceholderType:
case FK_ExplicitConstructor:
+ case FK_ArrayNeedsExplicitSizeOrInitList:
return false;
case FK_ReferenceInitOverloadFailed:
@@ -4449,6 +4450,17 @@
if (DestType->isDependentType() ||
Expr::hasAnyTypeDependentArguments(Args)) {
+ if (Args.size() == 1) {
+ Expr *Init = Args[0];
+ const InitListExpr *ILE = dyn_cast<InitListExpr>(Init);
+ if(!ILE || (ILE && !ILE->isStringLiteralInit() && ILE->getNumInits() == 0 )) {
+ if ( DestType->isIncompleteType()
+ || DestType->isIncompleteOrObjectType() ) {
+ SetFailed(FK_ArrayNeedsExplicitSizeOrInitList);
+ return;
+ }
+ }
+ }
SequenceKind = DependentSequence;
return;
}
@@ -6658,7 +6670,12 @@
S.Diag(CtorDecl->getLocation(), diag::note_constructor_declared_here);
break;
}
+ case FK_ArrayNeedsExplicitSizeOrInitList: {
+ S.Diag(Kind.getLocation(), diag::err_typecheck_incomplete_array_needs_initializer)
+ << Args[0]->getSourceRange();
+ break;
}
+ }
PrintInitLocationNote(S, Entity);
return true;
@@ -6788,6 +6805,9 @@
case FK_ExplicitConstructor:
OS << "list copy initialization chose explicit constructor";
break;
+ case FK_ArrayNeedsExplicitSizeOrInitList:
+ OS << "Variable with array type needs an explicit size or an initializer";
+ break;
}
OS << '\n';
return;
Index: llvm/tools/clang/include/clang/Sema/Initialization.h
===================================================================
--- llvm/tools/clang/include/clang/Sema/Initialization.h
+++ llvm/tools/clang/include/clang/Sema/Initialization.h
@@ -810,7 +810,9 @@
/// resolved by initialization.
FK_PlaceholderType,
/// \brief List-copy-initialization chose an explicit constructor.
- FK_ExplicitConstructor
+ FK_ExplicitConstructor,
+ /// \brief Variable with array type needs an explicit size or an initializer.
+ FK_ArrayNeedsExplicitSizeOrInitList
};
private:
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D1700.3.patch
Type: text/x-patch
Size: 2970 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20131029/416e83af/attachment.bin>
More information about the cfe-commits
mailing list