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
diff --git a/lib/Sema/SemaExprCXX.cpp b/lib/Sema/SemaExprCXX.cpp
index 5e7fb33..d4efa78 100644
--- a/lib/Sema/SemaExprCXX.cpp
+++ b/lib/Sema/SemaExprCXX.cpp
@@ -1010,10 +1010,13 @@
   // 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 @@
       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 3bdb3b6..654bed2 100644
--- a/lib/Sema/SemaType.cpp
+++ b/lib/Sema/SemaType.cpp
@@ -1267,6 +1267,13 @@
     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 a43811d..29f84da 100644
--- a/test/SemaObjC/property.m
+++ b/test/SemaObjC/property.m
@@ -74,3 +74,10 @@
 + (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 0b9c63e..1b6c0c5 100644
--- a/test/SemaObjCXX/properties.mm
+++ b/test/SemaObjCXX/properties.mm
@@ -31,3 +31,12 @@
   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}}
+}