Skip to content

[Sema] add cast from IncompleteArrayType to ConstantArrayType in TryReferenceListInitialization #65918

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,9 @@ Bug Fixes in This Version
(`#66047 <https://github.com/llvm/llvm-project/issues/66047>`_)
- Fix parser crash when dealing with ill-formed objective C++ header code. Fixes
(`#64836 <https://github.com/llvm/llvm-project/issues/64836>`_)
- Fix crash in implicit conversions from initialize list to arrays of unknown
bound for C++20. Fixes
(`#62945 <https://github.com/llvm/llvm-project/issues/62945>`_)
- Clang now allows an ``_Atomic`` qualified integer in a switch statement. Fixes
(`#65557 <https://github.com/llvm/llvm-project/issues/65557>`_)

Expand Down
1 change: 1 addition & 0 deletions clang/include/clang/AST/OperationKinds.def
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ CAST_OPERATION(LValueToRValue)
/// (possibly) adding qualifiers or removing noexcept.
/// int -> int
/// char** -> const char * const *
/// int[1] -> int[]
/// void () noexcept -> void ()
CAST_OPERATION(NoOp)

Expand Down
12 changes: 12 additions & 0 deletions clang/lib/Sema/SemaInit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "clang/AST/TypeLoc.h"
#include "clang/Basic/CharInfo.h"
#include "clang/Basic/SourceManager.h"
#include "clang/Basic/Specifiers.h"
#include "clang/Basic/TargetInfo.h"
#include "clang/Sema/Designator.h"
#include "clang/Sema/EnterExpressionEvaluationContext.h"
Expand Down Expand Up @@ -4528,6 +4529,17 @@ static void TryReferenceListInitialization(Sema &S,
if (Sequence) {
if (DestType->isRValueReferenceType() ||
(T1Quals.hasConst() && !T1Quals.hasVolatile())) {
if (S.getLangOpts().CPlusPlus20 &&
isa<IncompleteArrayType>(T1->getUnqualifiedDesugaredType()) &&
DestType->isRValueReferenceType()) {
// C++20 [dcl.init.list]p3.10:
// List-initialization of an object or reference of type T is defined as
// follows:
// ..., unless T is “reference to array of unknown bound of U”, in which
// case the type of the prvalue is the type of x in the declaration U
// x[] H, where H is the initializer list.
Sequence.AddQualificationConversionStep(cv1T1, clang::VK_PRValue);
}
Sequence.AddReferenceBindingStep(cv1T1IgnoreAS,
/*BindingTemporary=*/true);
if (T1Quals.hasAddressSpace())
Expand Down
9 changes: 9 additions & 0 deletions clang/test/CodeGenCXX/cxx20-p0388-unbound-ary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,13 @@ auto &frob2(int (&arp)[1]) {

return r2;
}

// CHECK-LABEL: @_ZN3One3fooEi
// CHECK-NEXT: entry:
// CHECK-NEXT: ret void
void foo(int a) {
auto f = [](int(&&)[]) {};
f({a});
}

} // namespace One