forked from OSchip/llvm-project
The array form of 'new' can never have initializers.
llvm-svn: 102917
This commit is contained in:
parent
ed088b7fe7
commit
c6bb0e117f
|
@ -2179,6 +2179,8 @@ def err_new_incomplete_type : Error<
|
|||
"allocation of incomplete type %0">;
|
||||
def err_new_array_nonconst : Error<
|
||||
"only the first dimension of an allocated array may have dynamic size">;
|
||||
def err_new_array_init_args : Error<
|
||||
"array 'new' cannot have initialization arguments">;
|
||||
def err_new_paren_array_nonconst : Error<
|
||||
"when type is in parentheses, array cannot have dynamic size">;
|
||||
def err_placement_new_non_placement_delete : Error<
|
||||
|
|
|
@ -738,6 +738,15 @@ Sema::BuildCXXNew(SourceLocation StartLoc, bool UseGlobal,
|
|||
unsigned NumConsArgs = ConstructorArgs.size();
|
||||
ASTOwningVector<&ActionBase::DeleteExpr> ConvertedConstructorArgs(*this);
|
||||
|
||||
// Array 'new' can't have any initializers.
|
||||
if (NumConsArgs && ArraySize) {
|
||||
SourceRange InitRange(ConsArgs[0]->getLocStart(),
|
||||
ConsArgs[NumConsArgs - 1]->getLocEnd());
|
||||
|
||||
Diag(StartLoc, diag::err_new_array_init_args) << InitRange;
|
||||
return ExprError();
|
||||
}
|
||||
|
||||
if (!AllocType->isDependentType() &&
|
||||
!Expr::hasAnyTypeDependentArguments(ConsArgs, NumConsArgs)) {
|
||||
// C++0x [expr.new]p15:
|
||||
|
|
|
@ -34,7 +34,6 @@ void good_news()
|
|||
S *ps = new S(1, 2, 3.4);
|
||||
ps = new (pf) (S)(1, 2, 3.4);
|
||||
S *(*paps)[2] = new S*[*pi][2];
|
||||
ps = new (S[3])(1, 2, 3.4);
|
||||
typedef int ia4[4];
|
||||
ia4 *pai = new (int[3][4]);
|
||||
pi = ::new int;
|
||||
|
@ -231,3 +230,23 @@ namespace PR5918 { // Look for template operator new overloads.
|
|||
(void)new(0) S;
|
||||
}
|
||||
}
|
||||
|
||||
namespace Test1 {
|
||||
|
||||
void f() {
|
||||
(void)new int[10](1, 2); // expected-error {{array 'new' cannot have initialization arguments}}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void g(unsigned i) {
|
||||
(void)new T[1](i); // expected-error {{array 'new' cannot have initialization arguments}}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void h(unsigned i) {
|
||||
(void)new T(i); // expected-error {{array 'new' cannot have initialization arguments}}
|
||||
}
|
||||
template void h<unsigned>(unsigned);
|
||||
template void h<unsigned[10]>(unsigned); // expected-note {{in instantiation of function template specialization 'Test1::h<unsigned int [10]>' requested here}}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue