Skip to content

Commit e6ae81b

Browse files
author
Anders Carlsson
committed
Correctly diagnose array 'new' with initialization arguments when the new type is a typedef to an array type.
llvm-svn: 103909
1 parent cda95f4 commit e6ae81b

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

clang/lib/Sema/SemaExprCXX.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -760,7 +760,7 @@ Sema::BuildCXXNew(SourceLocation StartLoc, bool UseGlobal,
760760
ASTOwningVector<&ActionBase::DeleteExpr> ConvertedConstructorArgs(*this);
761761

762762
// Array 'new' can't have any initializers.
763-
if (NumConsArgs && ArraySize) {
763+
if (NumConsArgs && (ResultType->isArrayType() || ArraySize)) {
764764
SourceRange InitRange(ConsArgs[0]->getLocStart(),
765765
ConsArgs[NumConsArgs - 1]->getLocEnd());
766766

clang/test/SemaCXX/new-delete.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,9 @@ namespace Test1 {
245245

246246
void f() {
247247
(void)new int[10](1, 2); // expected-error {{array 'new' cannot have initialization arguments}}
248+
249+
typedef int T[10];
250+
(void)new T(1, 2); // expected-error {{array 'new' cannot have initialization arguments}}
248251
}
249252

250253
template<typename T>

0 commit comments

Comments
 (0)