aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn McCall <rjmccall@apple.com>2012-01-11 00:14:46 +0000
committerJohn McCall <rjmccall@apple.com>2012-01-11 00:14:46 +0000
commit806054db6653d29cb0d9692df3612cbcd03d0530 (patch)
treeec8e7db01c48b0b65e6170409e0390816364a734
parent9db0a5e7e360d8048c83ee1c46a88c4172182791 (diff)
Do placeholder conversions on array bounds in both declarators and
new-expressions. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@147900 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Sema/SemaExprCXX.cpp11
-rw-r--r--lib/Sema/SemaType.cpp7
-rw-r--r--test/SemaObjC/property.m7
-rw-r--r--test/SemaObjCXX/properties.mm9
4 files changed, 30 insertions, 4 deletions
diff --git a/lib/Sema/SemaExprCXX.cpp b/lib/Sema/SemaExprCXX.cpp
index 5e7fb33d05..d4efa78b23 100644
--- a/lib/Sema/SemaExprCXX.cpp
+++ b/lib/Sema/SemaExprCXX.cpp
@@ -1010,10 +1010,13 @@ Sema::BuildCXXNew(SourceLocation StartLoc, bool UseGlobal,
// C++ 5.3.4p6: "The expression in a direct-new-declarator shall have integral
// or enumeration type with a non-negative value."
if (ArraySize && !ArraySize->isTypeDependent()) {
+ // Eliminate placeholders.
+ ExprResult ConvertedSize = CheckPlaceholderExpr(ArraySize);
+ if (ConvertedSize.isInvalid())
+ return ExprError();
+ ArraySize = ConvertedSize.take();
- QualType SizeType = ArraySize->getType();
-
- ExprResult ConvertedSize = ConvertToIntegralOrEnumerationType(
+ ConvertedSize = ConvertToIntegralOrEnumerationType(
StartLoc, ArraySize,
PDiag(diag::err_array_size_not_integral),
PDiag(diag::err_array_size_incomplete_type)
@@ -1029,7 +1032,7 @@ Sema::BuildCXXNew(SourceLocation StartLoc, bool UseGlobal,
return ExprError();
ArraySize = ConvertedSize.take();
- SizeType = ArraySize->getType();
+ QualType SizeType = ArraySize->getType();
if (!SizeType->isIntegralOrUnscopedEnumerationType())
return ExprError();
diff --git a/lib/Sema/SemaType.cpp b/lib/Sema/SemaType.cpp
index 3bdb3b6d2c..654bed270b 100644
--- a/lib/Sema/SemaType.cpp
+++ b/lib/Sema/SemaType.cpp
@@ -1267,6 +1267,13 @@ QualType Sema::BuildArrayType(QualType T, ArrayType::ArraySizeModifier ASM,
return QualType();
}
+ // Do placeholder conversions on the array size expression.
+ if (ArraySize && ArraySize->hasPlaceholderType()) {
+ ExprResult Result = CheckPlaceholderExpr(ArraySize);
+ if (Result.isInvalid()) return QualType();
+ ArraySize = Result.take();
+ }
+
// Do lvalue-to-rvalue conversions on the array size expression.
if (ArraySize && !ArraySize->isRValue()) {
ExprResult Result = DefaultLvalueConversion(ArraySize);
diff --git a/test/SemaObjC/property.m b/test/SemaObjC/property.m
index a43811d824..29f84daef9 100644
--- a/test/SemaObjC/property.m
+++ b/test/SemaObjC/property.m
@@ -74,3 +74,10 @@ Class test6_getClass();
+ (float) globalValue { return 5.0f; }
+ (float) gv { return test6_getClass().globalValue; }
@end
+
+@interface Test7
+@property unsigned length;
+@end
+void test7(Test7 *t) {
+ char data[t.length] = {}; // expected-error {{variable-sized object may not be initialized}}
+}
diff --git a/test/SemaObjCXX/properties.mm b/test/SemaObjCXX/properties.mm
index 0b9c63e30d..1b6c0c54cd 100644
--- a/test/SemaObjCXX/properties.mm
+++ b/test/SemaObjCXX/properties.mm
@@ -31,3 +31,12 @@ void test2(Test2 *a) {
auto y = a.y; // expected-error {{expected getter method not found on object of type 'Test2 *'}} expected-error {{variable 'y' with type 'auto' has incompatible initializer of type}}
auto z = a.z;
}
+
+// rdar://problem/10672108
+@interface Test3
+- (int) length;
+@end
+void test3(Test3 *t) {
+ char vla[t.length] = {};
+ char *heaparray = new char[t.length]; // expected-error {{variable-sized object may not be initialized}}
+}