hokein updated this revision to Diff 332925. hokein added a comment. - jrefine the fix of the crash: if the element type of an variable-length array
is incomplete, the array type is incomplete; - simplify the testcase Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D99165/new/ https://reviews.llvm.org/D99165 Files: clang/lib/AST/Type.cpp clang/test/SemaCXX/cxx0x-initializer-aggregates.cpp Index: clang/test/SemaCXX/cxx0x-initializer-aggregates.cpp =================================================================== --- clang/test/SemaCXX/cxx0x-initializer-aggregates.cpp +++ clang/test/SemaCXX/cxx0x-initializer-aggregates.cpp @@ -133,3 +133,10 @@ 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}} +} +} Index: clang/lib/AST/Type.cpp =================================================================== --- clang/lib/AST/Type.cpp +++ clang/lib/AST/Type.cpp @@ -2229,10 +2229,11 @@ 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:
Index: clang/test/SemaCXX/cxx0x-initializer-aggregates.cpp =================================================================== --- clang/test/SemaCXX/cxx0x-initializer-aggregates.cpp +++ clang/test/SemaCXX/cxx0x-initializer-aggregates.cpp @@ -133,3 +133,10 @@ 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}} +} +} Index: clang/lib/AST/Type.cpp =================================================================== --- clang/lib/AST/Type.cpp +++ clang/lib/AST/Type.cpp @@ -2229,10 +2229,11 @@ 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:
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits