diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -634,6 +634,8 @@ that construct (`#62133 _`). - Fix crash caused by PseudoObjectExprBitfields: NumSubExprs overflow. (`#63169 _`) +- Fix crash when casting an object to an array type. + (`#63758 _`) Bug Fixes to Compiler Builtins ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/clang/lib/Sema/SemaCast.cpp b/clang/lib/Sema/SemaCast.cpp --- a/clang/lib/Sema/SemaCast.cpp +++ b/clang/lib/Sema/SemaCast.cpp @@ -454,9 +454,18 @@ switch (sequence.getFailureKind()) { default: return false; + case InitializationSequence::FK_ParenthesizedListInitFailed: + // In C++20, if the underlying destination type is a RecordType, then we + // attempt to perform parentesized aggregate initialization if constructor + // overload fails. If that fails, then we'll generate the diagnostics from + // the failed overload result from the previous constructor overload. Array + // initialization, however, is not done after attempting constructor + // overloading, so we bail out as there won't be a failed overload result. + if (destType->isArrayType()) + return false; + break; case InitializationSequence::FK_ConstructorOverloadFailed: case InitializationSequence::FK_UserConversionOverloadFailed: - case InitializationSequence::FK_ParenthesizedListInitFailed: break; } diff --git a/clang/test/SemaCXX/paren-list-agg-init.cpp b/clang/test/SemaCXX/paren-list-agg-init.cpp --- a/clang/test/SemaCXX/paren-list-agg-init.cpp +++ b/clang/test/SemaCXX/paren-list-agg-init.cpp @@ -294,3 +294,8 @@ } } + +namespace gh63758 { + struct S {} s; + auto words = (char[])s; // expected-error {{C-style cast from 'struct S' to 'char[]' is not allowed}} +};