[clang] cfc36bf - [clang] Treat variable-length array of incomplete element type as
Haojian Wu via cfe-commits
cfe-commits at lists.llvm.org
Wed Mar 24 06:22:35 PDT 2021
Author: Haojian Wu
Date: 2021-03-24T14:22:15+01:00
New Revision: cfc36bf0179435ecbd489761bd7d5dae00846c87
URL: https://github.com/llvm/llvm-project/commit/cfc36bf0179435ecbd489761bd7d5dae00846c87
DIFF: https://github.com/llvm/llvm-project/commit/cfc36bf0179435ecbd489761bd7d5dae00846c87.diff
LOG: [clang] Treat variable-length array of incomplete element type as
incomplete type.
Differential Revision: https://reviews.llvm.org/D99165
Added:
Modified:
clang/lib/AST/Type.cpp
clang/test/SemaCXX/cxx0x-initializer-aggregates.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index 51289ce45ab9..611c30d9c767 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -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:
diff --git a/clang/test/SemaCXX/cxx0x-initializer-aggregates.cpp b/clang/test/SemaCXX/cxx0x-initializer-aggregates.cpp
index 7a7b92b7d04f..94fee530aea6 100644
--- a/clang/test/SemaCXX/cxx0x-initializer-aggregates.cpp
+++ b/clang/test/SemaCXX/cxx0x-initializer-aggregates.cpp
@@ -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}}
+}
+}
More information about the cfe-commits
mailing list