Use the C++11 POD definition in C++11 mode to determine whether one
can create a VLA of class type. Fixes <rdar://problem/12151822>.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171783 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaType.cpp b/lib/Sema/SemaType.cpp
index 1bdd7c3..ad70468 100644
--- a/lib/Sema/SemaType.cpp
+++ b/lib/Sema/SemaType.cpp
@@ -1269,6 +1269,12 @@
                                            S.LangOpts.GNUMode).isInvalid();
 }
 
+/// \brief Determine whether the given type is a POD or standard-layout type,
+/// as appropriate for the C++ language options.
+static bool isPODType(QualType T, ASTContext &Context) {
+  return Context.getLangOpts().CPlusPlus11? T.isCXX11PODType(Context)
+                                          : T.isCXX98PODType(Context);
+}
 
 /// \brief Build an array type.
 ///
@@ -1442,8 +1448,8 @@
       // Prohibit the use of non-POD types in VLAs.
       QualType BaseT = Context.getBaseElementType(T);
       if (!T->isDependentType() &&
-          !BaseT.isPODType(Context) &&
-          !BaseT->isObjCLifetimeType()) {
+          !BaseT->isObjCLifetimeType() &&
+          !isPODType(BaseT, Context)) {
         Diag(Loc, diag::err_vla_non_pod)
           << BaseT;
         return QualType();
diff --git a/test/SemaCXX/c99-variable-length-array-cxx11.cpp b/test/SemaCXX/c99-variable-length-array-cxx11.cpp
new file mode 100644
index 0000000..b740e39
--- /dev/null
+++ b/test/SemaCXX/c99-variable-length-array-cxx11.cpp
@@ -0,0 +1,26 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 -Wvla %s
+struct StillPOD {
+  StillPOD() = default;
+};
+
+struct StillPOD2 {
+  StillPOD np;
+};
+
+struct NonPOD {
+  NonPOD(int) {}
+};
+
+struct POD {
+  int x;
+  int y;
+};
+
+// We allow VLAs of POD types, only.
+void vla(int N) {
+  int array1[N]; // expected-warning{{variable length arrays are a C99 feature}}
+  POD array2[N]; // expected-warning{{variable length arrays are a C99 feature}}
+  StillPOD array3[N]; // expected-warning{{variable length arrays are a C99 feature}}
+  StillPOD2 array4[N][3]; // expected-warning{{variable length arrays are a C99 feature}}
+  NonPOD array5[N]; // expected-error{{variable length array of non-POD element type 'NonPOD'}}
+}