From: Sebastian Redl Date: Fri, 17 Feb 2012 08:42:32 +0000 (+0000) Subject: Don't allow non-empty ParenListExprs as array-new initializers. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1f27805fe4f5463fd5b4d5396affe1ef23320688;p=clang Don't allow non-empty ParenListExprs as array-new initializers. Don't know what I was thinking there. Fixes PR12023. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@150804 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaExprCXX.cpp b/lib/Sema/SemaExprCXX.cpp index 1f50984996..ca8411918a 100644 --- a/lib/Sema/SemaExprCXX.cpp +++ b/lib/Sema/SemaExprCXX.cpp @@ -981,11 +981,8 @@ static bool isLegalArrayNewInitializer(CXXNewExpr::InitializationStyle Style, Expr *Init) { if (!Init) return true; - if (ParenListExpr *PLE = dyn_cast(Init)) { - if (PLE->getNumExprs() != 1) - return PLE->getNumExprs() == 0; - Init = PLE->getExpr(0); - } + if (ParenListExpr *PLE = dyn_cast(Init)) + return PLE->getNumExprs() == 0; if (isa(Init)) return true; else if (CXXConstructExpr *CCE = dyn_cast(Init)) diff --git a/test/SemaCXX/new-delete.cpp b/test/SemaCXX/new-delete.cpp index dfe880e34b..d355c7cc51 100644 --- a/test/SemaCXX/new-delete.cpp +++ b/test/SemaCXX/new-delete.cpp @@ -446,3 +446,17 @@ namespace r150682 { } } + +namespace P12023 { + struct CopyCounter + { + CopyCounter(); + CopyCounter(const CopyCounter&); + }; + + int main() + { + CopyCounter* f = new CopyCounter[10](CopyCounter()); // expected-error {{cannot have initialization arguments}} + return 0; + } +}