<br><br><div class="gmail_quote">Le 16 février 2012 13:59, Sebastian Redl <span dir="ltr"><<a href="mailto:sebastian.redl@getdesigned.at">sebastian.redl@getdesigned.at</a>></span> a écrit :<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Author: cornedbee<br>
Date: Thu Feb 16 06:59:47 2012<br>
New Revision: 150688<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=150688&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=150688&view=rev</a><br>
Log:<br>
Proper checking of list-initializers for array new expressions.<br>
<br>
This finishes generalized initializer support in Sema.<br>
<br></blockquote><div><br>Just to point that Richard just started the budgeoning Release notes for 3.1, it may be worth mentioning this support there ?<br><br>-- Matthieu<br> </div><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">

Modified:<br>
    cfe/trunk/lib/Sema/SemaExprCXX.cpp<br>
    cfe/trunk/test/SemaCXX/new-delete-cxx0x.cpp<br>
<br>
Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=150688&r1=150687&r2=150688&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=150688&r1=150687&r2=150688&view=diff</a><br>

==============================================================================<br>
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)<br>
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Thu Feb 16 06:59:47 2012<br>
@@ -30,6 +30,7 @@<br>
 #include "clang/Basic/TargetInfo.h"<br>
 #include "clang/Lex/Preprocessor.h"<br>
 #include "TypeLocBuilder.h"<br>
+#include "llvm/ADT/APInt.h"<br>
 #include "llvm/ADT/STLExtras.h"<br>
 #include "llvm/Support/ErrorHandling.h"<br>
 using namespace clang;<br>
@@ -976,7 +977,8 @@<br>
                      TypeContainsAuto);<br>
 }<br>
<br>
-static bool isLegalArrayNewInitializer(Expr *Init) {<br>
+static bool isLegalArrayNewInitializer(CXXNewExpr::InitializationStyle Style,<br>
+                                       Expr *Init) {<br>
   if (!Init)<br>
     return true;<br>
   if (ParenListExpr *PLE = dyn_cast<ParenListExpr>(Init)) {<br>
@@ -989,6 +991,11 @@<br>
   else if (CXXConstructExpr *CCE = dyn_cast<CXXConstructExpr>(Init))<br>
     return !CCE->isListInitialization() &&<br>
            CCE->getConstructor()->isDefaultConstructor();<br>
+  else if (Style == CXXNewExpr::ListInit) {<br>
+    assert(isa<InitListExpr>(Init) &&<br>
+           "Shouldn't create list CXXConstructExprs for arrays.");<br>
+    return true;<br>
+  }<br>
   return false;<br>
 }<br>
<br>
@@ -1240,14 +1247,26 @@<br>
     }<br>
   }<br>
<br>
+  QualType InitType = AllocType;<br>
   // Array 'new' can't have any initializers except empty parentheses.<br>
-  if (!isLegalArrayNewInitializer(Initializer) &&<br>
-      (ResultType->isArrayType() || ArraySize)) {<br>
-    SourceRange InitRange(Inits[0]->getLocStart(),<br>
-                          Inits[NumInits - 1]->getLocEnd());<br>
-<br>
-    Diag(StartLoc, diag::err_new_array_init_args) << InitRange;<br>
-    return ExprError();<br>
+  // Initializer lists are also allowed, in C++11. Rely on the parser for the<br>
+  // dialect distinction.<br>
+  if (ResultType->isArrayType() || ArraySize) {<br>
+    if (!isLegalArrayNewInitializer(initStyle, Initializer)) {<br>
+      SourceRange InitRange(Inits[0]->getLocStart(),<br>
+                            Inits[NumInits - 1]->getLocEnd());<br>
+      Diag(StartLoc, diag::err_new_array_init_args) << InitRange;<br>
+      return ExprError();<br>
+    }<br>
+    if (InitListExpr *ILE = dyn_cast_or_null<InitListExpr>(Initializer)) {<br>
+      // We do the initialization typechecking against the array type<br>
+      // corresponding to the number of initializers + 1 (to also check<br>
+      // default-initialization).<br>
+      unsigned NumElements = ILE->getNumInits() + 1;<br>
+      InitType = Context.getConstantArrayType(AllocType,<br>
+          llvm::APInt(Context.getTypeSize(Context.getSizeType()), NumElements),<br>
+                                              ArrayType::Normal, 0);<br>
+    }<br>
   }<br>
<br>
   if (!AllocType->isDependentType() &&<br>
@@ -1270,7 +1289,7 @@<br>
                                                  DirectInitRange.getEnd());<br>
<br>
     InitializedEntity Entity<br>
-      = InitializedEntity::InitializeNew(StartLoc, AllocType);<br>
+      = InitializedEntity::InitializeNew(StartLoc, InitType);<br>
     InitializationSequence InitSeq(*this, Entity, Kind, Inits, NumInits);<br>
     ExprResult FullInit = InitSeq.Perform(*this, Entity, Kind,<br>
                                           MultiExprArg(Inits, NumInits));<br>
<br>
Modified: cfe/trunk/test/SemaCXX/new-delete-cxx0x.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/new-delete-cxx0x.cpp?rev=150688&r1=150687&r2=150688&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/new-delete-cxx0x.cpp?rev=150688&r1=150687&r2=150688&view=diff</a><br>

==============================================================================<br>
--- cfe/trunk/test/SemaCXX/new-delete-cxx0x.cpp (original)<br>
+++ cfe/trunk/test/SemaCXX/new-delete-cxx0x.cpp Thu Feb 16 06:59:47 2012<br>
@@ -7,3 +7,20 @@<br>
   (void)new int[-1]; // expected-warning {{array size is negative}}<br>
   (void)new int[2000000000]; // expected-warning {{array is too large}}<br>
 }<br>
+<br>
+<br>
+struct S {<br>
+  S(int);<br>
+  S();<br>
+  ~S();<br>
+};<br>
+<br>
+struct T { // expected-note 2 {{not viable}}<br>
+  T(int); // expected-note {{not viable}}<br>
+};<br>
+<br>
+void fn() {<br>
+  (void) new int[2] {1, 2};<br>
+  (void) new S[2] {1, 2};<br>
+  (void) new T[2] {1, 2}; // expected-error {{no matching constructor}}<br>
+}<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
</blockquote></div><br>