[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(); return !Rec->isCompleteDefinition();
} }
case ConstantArray: case ConstantArray:
case VariableArray:
// An array is incomplete if its element type is incomplete // An array is incomplete if its element type is incomplete
// (C++ [dcl.array]p1). // (C++ [dcl.array]p1).
// We don't handle variable arrays (they're not allowed in C++) or // We don't handle dependent-sized arrays (dependent types are never treated
// dependent-sized arrays (dependent types are never treated as incomplete). // as incomplete).
return cast<ArrayType>(CanonicalType)->getElementType() return cast<ArrayType>(CanonicalType)->getElementType()
->isIncompleteType(Def); ->isIncompleteType(Def);
case IncompleteArray: case IncompleteArray:

View File

@ -133,3 +133,10 @@ namespace array_addressof {
namespace PR24816 { namespace PR24816 {
struct { int i; } ne = {{0, 1}}; // expected-error{{excess elements in scalar initializer}} 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}}
}
}