This is an archive of the discontinued LLVM Phabricator instance.

[clang] Fix a crash when casting to an array type
ClosedPublic

Authored by ayzhao on Jul 17 2023, 3:57 PM.

Details

Summary

In C++20, if Clang fails to perform constructor overload on a
RecordType, then Clang will try to perform parentesized aggregate
initialization. If that fails and the initialization was attempted as
part of a cast, then we should get the diagnostics from the failed
constructor overload attempt. However, we don't attempt constructor
overloading for arrays, so previously, if we try to diagnose an
overloaded cast for a parenthesized aggregate initialization of an
array, we crash. To fix this, we now exit tryDiagnoseOverloadedCast(...)
for failed parentesized list initialization if the destination type is
an array.

Fixes #63758

Diff Detail

Event Timeline

ayzhao created this revision.Jul 17 2023, 3:57 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 17 2023, 3:57 PM
ayzhao requested review of this revision.Jul 17 2023, 3:57 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 17 2023, 3:57 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
shafik added a subscriber: shafik.Jul 17 2023, 9:15 PM
shafik added inline comments.
clang/lib/Sema/SemaCast.cpp
458

Can you quote the sections in the standard that say this?

ayzhao updated this revision to Diff 541588.Jul 18 2023, 9:03 AM
ayzhao marked an inline comment as done.

quote C++20 standard

aaron.ballman accepted this revision.Jul 18 2023, 9:39 AM

LGTM, thank you for the fix!

This revision is now accepted and ready to land.Jul 18 2023, 9:39 AM
This revision was landed with ongoing or failed builds.Jul 18 2023, 9:48 AM
This revision was automatically updated to reflect the committed changes.