[PATCH] [Patch] Fix for assertion when incomplete array type is used as template param
jyoti allur
jyoti.yalamanchili at gmail.com
Wed Oct 16 08:57:12 PDT 2013
Added a patch to prevent variable definition creation for incomplete types with zero initializer elements to prevent the mentioned assertion and throw diagnostic.
Patch in
llvm/tools/clang/lib/SemaSemaTemplateInstantiateDecl.cpp
Please let me know your review comments.
Thanks.
Hi dblaikie, rsmith,
http://llvm-reviews.chandlerc.com/D1700
CHANGE SINCE LAST DIFF
http://llvm-reviews.chandlerc.com/D1700?vs=4342&id=4957#toc
Files:
llvm/tools/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
llvm/tools/clang/test/SemaCXX/cxx0x-function-template-specialization.cpp
Index: llvm/tools/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
===================================================================
--- llvm/tools/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ llvm/tools/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -364,6 +364,21 @@
if (SubstQualifier(D, Var))
return 0;
+ if (D->getInit() && !InstantiatingVarTemplate) {
+ const Expr* Arg = D->getInit();
+ const InitListExpr *ILE = dyn_cast<InitListExpr>(Arg);
+ if(!ILE || (ILE && !ILE->isStringLiteralInit() && ILE->getNumInits() == 0 )) {
+ if (D->getType()->isIncompleteType() || D->getType()->isIncompleteOrObjectType() ) {
+ if (SemaRef.RequireCompleteType(Var->getLocation(),
+ Var->getType(), diag::err_typecheck_incomplete_array_needs_initializer)) {
+ Var->setInvalidDecl();
+ return 0;
+ }
+ }
+ }
+ }
+
+
SemaRef.BuildVariableInstantiation(Var, D, TemplateArgs, LateAttrs, Owner,
StartingScope, InstantiatingVarTemplate);
return Var;
Index: llvm/tools/clang/test/SemaCXX/cxx0x-function-template-specialization.cpp
===================================================================
--- llvm/tools/clang/test/SemaCXX/cxx0x-function-template-specialization.cpp
+++ llvm/tools/clang/test/SemaCXX/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}}
+}
+
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D1700.2.patch
Type: text/x-patch
Size: 1827 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20131016/da25b3b7/attachment.bin>
More information about the cfe-commits
mailing list