Skip to content

Commit d89d3a6

Browse files
authored
[Sema] add cast from IncompleteArrayType to ConstantArrayType in TryReferenceListInitialization (#65918)
1 parent a54f31f commit d89d3a6

File tree

4 files changed

+25
-0
lines changed

4 files changed

+25
-0
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,9 @@ Bug Fixes in This Version
264264
(`#66047 <https://github.com/llvm/llvm-project/issues/66047>`_)
265265
- Fix parser crash when dealing with ill-formed objective C++ header code. Fixes
266266
(`#64836 <https://github.com/llvm/llvm-project/issues/64836>`_)
267+
- Fix crash in implicit conversions from initialize list to arrays of unknown
268+
bound for C++20. Fixes
269+
(`#62945 <https://github.com/llvm/llvm-project/issues/62945>`_)
267270
- Clang now allows an ``_Atomic`` qualified integer in a switch statement. Fixes
268271
(`#65557 <https://github.com/llvm/llvm-project/issues/65557>`_)
269272
- Fixes crash when trying to obtain the common sugared type of

clang/include/clang/AST/OperationKinds.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ CAST_OPERATION(LValueToRValue)
8080
/// (possibly) adding qualifiers or removing noexcept.
8181
/// int -> int
8282
/// char** -> const char * const *
83+
/// int[1] -> int[]
8384
/// void () noexcept -> void ()
8485
CAST_OPERATION(NoOp)
8586

clang/lib/Sema/SemaInit.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "clang/AST/TypeLoc.h"
1919
#include "clang/Basic/CharInfo.h"
2020
#include "clang/Basic/SourceManager.h"
21+
#include "clang/Basic/Specifiers.h"
2122
#include "clang/Basic/TargetInfo.h"
2223
#include "clang/Sema/Designator.h"
2324
#include "clang/Sema/EnterExpressionEvaluationContext.h"
@@ -4528,6 +4529,17 @@ static void TryReferenceListInitialization(Sema &S,
45284529
if (Sequence) {
45294530
if (DestType->isRValueReferenceType() ||
45304531
(T1Quals.hasConst() && !T1Quals.hasVolatile())) {
4532+
if (S.getLangOpts().CPlusPlus20 &&
4533+
isa<IncompleteArrayType>(T1->getUnqualifiedDesugaredType()) &&
4534+
DestType->isRValueReferenceType()) {
4535+
// C++20 [dcl.init.list]p3.10:
4536+
// List-initialization of an object or reference of type T is defined as
4537+
// follows:
4538+
// ..., unless T is “reference to array of unknown bound of U”, in which
4539+
// case the type of the prvalue is the type of x in the declaration U
4540+
// x[] H, where H is the initializer list.
4541+
Sequence.AddQualificationConversionStep(cv1T1, clang::VK_PRValue);
4542+
}
45314543
Sequence.AddReferenceBindingStep(cv1T1IgnoreAS,
45324544
/*BindingTemporary=*/true);
45334545
if (T1Quals.hasAddressSpace())

clang/test/CodeGenCXX/cxx20-p0388-unbound-ary.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,13 @@ auto &frob2(int (&arp)[1]) {
2323

2424
return r2;
2525
}
26+
27+
// CHECK-LABEL: @_ZN3One3fooEi
28+
// CHECK-NEXT: entry:
29+
// CHECK-NEXT: ret void
30+
void foo(int a) {
31+
auto f = [](int(&&)[]) {};
32+
f({a});
33+
}
34+
2635
} // namespace One

0 commit comments

Comments
 (0)