diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp index c2ff2238d5fd..f9f6cee994ec 100644 --- a/clang/lib/Sema/SemaType.cpp +++ b/clang/lib/Sema/SemaType.cpp @@ -1590,6 +1590,7 @@ QualType Sema::BuildArrayType(QualType T, ArrayType::ArraySizeModifier ASM, // Prohibit the use of non-POD types in VLAs. QualType BaseT = Context.getBaseElementType(T); if (!T->isDependentType() && + !RequireCompleteType(Loc, BaseT, 0) && !BaseT.isPODType(Context) && !BaseT->isObjCLifetimeType()) { Diag(Loc, diag::err_vla_non_pod) diff --git a/clang/test/SemaCXX/vla.cpp b/clang/test/SemaCXX/vla.cpp index d63b6335f453..dae6450553aa 100644 --- a/clang/test/SemaCXX/vla.cpp +++ b/clang/test/SemaCXX/vla.cpp @@ -3,3 +3,17 @@ // PR11925 int n; int (&f())[n]; // expected-error {{function declaration cannot have variably modified type}} + +namespace PR18581 { + template struct pod {}; + template struct error { + typename T::error e; // expected-error {{cannot be used prior to '::'}} + }; + struct incomplete; // expected-note {{forward declaration}} + + void f(int n) { + pod a[n]; + error b[n]; // expected-note {{instantiation}} + incomplete c[n]; // expected-error {{incomplete}} + } +}