Skip to content

Commit

Permalink
[clang] Treat variable-length array of incomplete element type as
Browse files Browse the repository at this point in the history
incomplete type.

Differential Revision: https://reviews.llvm.org/D99165
  • Loading branch information
hokein committed Mar 24, 2021
1 parent 8140d0e commit cfc36bf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
5 changes: 3 additions & 2 deletions clang/lib/AST/Type.cpp
Expand Up @@ -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:
Expand Down
7 changes: 7 additions & 0 deletions clang/test/SemaCXX/cxx0x-initializer-aggregates.cpp
Expand Up @@ -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}}
}
}

0 comments on commit cfc36bf

Please sign in to comment.