[clang] Treat variable-length array of incomplete element type as

incomplete type.

Differential Revision: https://reviews.llvm.org/D99165
This commit is contained in:
Haojian Wu 2021-03-23 11:16:57 +01:00
parent 8140d0ec4a
commit cfc36bf017
2 changed files with 10 additions and 2 deletions

View File

@ -2229,10 +2229,11 @@ bool Type::isIncompleteType(NamedDecl **Def) const {
return !Rec->isCompleteDefinition();
}
case ConstantArray:
case VariableArray:
// An array is incomplete if its element type is incomplete
// (C++ [dcl.array]p1).
// We don't handle variable arrays (they're not allowed in C++) or
// dependent-sized arrays (dependent types are never treated as incomplete).
// We don't handle dependent-sized arrays (dependent types are never treated
// as incomplete).
return cast<ArrayType>(CanonicalType)->getElementType()
->isIncompleteType(Def);
case IncompleteArray:

View File

@ -133,3 +133,10 @@ namespace array_addressof {
namespace PR24816 {
struct { int i; } ne = {{0, 1}}; // expected-error{{excess elements in scalar initializer}}
}
namespace no_crash {
class Foo; // expected-note {{forward declaration}}
void test(int size) {
Foo array[size] = {0}; // expected-error {{variable has incomplete type}}
}
}