From e6ae81b0a201fc1613d3c57b06c2450d0f26ccba Mon Sep 17 00:00:00 2001 From: Anders Carlsson Date: Sun, 16 May 2010 16:24:20 +0000 Subject: [PATCH] Correctly diagnose array 'new' with initialization arguments when the new type is a typedef to an array type. llvm-svn: 103909 --- clang/lib/Sema/SemaExprCXX.cpp | 2 +- clang/test/SemaCXX/new-delete.cpp | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp index 01da9c1c8ff7..f337a429ca72 100644 --- a/clang/lib/Sema/SemaExprCXX.cpp +++ b/clang/lib/Sema/SemaExprCXX.cpp @@ -760,7 +760,7 @@ Sema::BuildCXXNew(SourceLocation StartLoc, bool UseGlobal, ASTOwningVector<&ActionBase::DeleteExpr> ConvertedConstructorArgs(*this); // Array 'new' can't have any initializers. - if (NumConsArgs && ArraySize) { + if (NumConsArgs && (ResultType->isArrayType() || ArraySize)) { SourceRange InitRange(ConsArgs[0]->getLocStart(), ConsArgs[NumConsArgs - 1]->getLocEnd()); diff --git a/clang/test/SemaCXX/new-delete.cpp b/clang/test/SemaCXX/new-delete.cpp index 7b9b9d497ff4..8c9719b750ee 100644 --- a/clang/test/SemaCXX/new-delete.cpp +++ b/clang/test/SemaCXX/new-delete.cpp @@ -245,6 +245,9 @@ namespace Test1 { void f() { (void)new int[10](1, 2); // expected-error {{array 'new' cannot have initialization arguments}} + + typedef int T[10]; + (void)new T(1, 2); // expected-error {{array 'new' cannot have initialization arguments}} } template