[cfe-commits] r103908 - in /cfe/trunk: lib/Sema/SemaExprCXX.cpp test/SemaCXX/new-delete.cpp
Douglas Gregor
dgregor at apple.com
Sun May 16 09:01:03 PDT 2010
Author: dgregor
Date: Sun May 16 11:01:03 2010
New Revision: 103908
URL: http://llvm.org/viewvc/llvm-project?rev=103908&view=rev
Log:
When the type-id or new-type-id of a C++ "new" expression is a typedef
of an array type, use the outermost array bound as the number of
elements to allocate. Fixes PR7147.
Modified:
cfe/trunk/lib/Sema/SemaExprCXX.cpp
cfe/trunk/test/SemaCXX/new-delete.cpp
Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=103908&r1=103907&r2=103908&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Sun May 16 11:01:03 2010
@@ -680,10 +680,19 @@
if (CheckAllocatedType(AllocType, TypeLoc, TypeRange))
return ExprError();
- QualType ResultType = Context.getPointerType(AllocType);
+ // Per C++0x [expr.new]p5, the type being constructed may be a
+ // typedef of an array type.
+ if (!ArraySizeE.get()) {
+ if (const ConstantArrayType *Array
+ = Context.getAsConstantArrayType(AllocType)) {
+ ArraySizeE = Owned(new (Context) IntegerLiteral(Array->getSize(),
+ Context.getSizeType(),
+ TypeRange.getEnd()));
+ AllocType = Array->getElementType();
+ }
+ }
- // That every array dimension except the first is constant was already
- // checked by the type check above.
+ QualType ResultType = Context.getPointerType(AllocType);
// C++ 5.3.4p6: "The expression in a direct-new-declarator shall have integral
// or enumeration type with a non-negative value."
Modified: cfe/trunk/test/SemaCXX/new-delete.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/new-delete.cpp?rev=103908&r1=103907&r2=103908&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/new-delete.cpp (original)
+++ cfe/trunk/test/SemaCXX/new-delete.cpp Sun May 16 11:01:03 2010
@@ -24,6 +24,8 @@
void* operator new(size_t, float*); // expected-note 3 {{candidate}}
void* operator new(size_t, S); // expected-note 2 {{candidate}}
+struct foo { };
+
void good_news()
{
int *pi = new int;
@@ -43,6 +45,14 @@
pi = new (S(1.0f, 2)) int;
(void)new int[true];
+
+ // PR7147
+ typedef int a[2];
+ foo* f1 = new foo;
+ foo* f2 = new foo[2];
+ typedef foo x[2];
+ typedef foo y[2][2];
+ x* f3 = new y;
}
struct abstract {
More information about the cfe-commits
mailing list