Skip to content

Commit

Permalink
[C++20] [Modules] Handling capturing strucuted bindings
Browse files Browse the repository at this point in the history
Close #72828.

This should be an overlook that we extend the type of captures but we
forgot to fix it in deserializer side.
  • Loading branch information
ChuanqiXu9 committed Nov 29, 2023
1 parent e399a31 commit 649e811
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion clang/lib/Serialization/ASTReaderDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2032,7 +2032,7 @@ void ASTDeclReader::ReadCXXDefinitionData(
break;
case LCK_ByCopy:
case LCK_ByRef:
auto *Var = readDeclAs<VarDecl>();
auto *Var = readDeclAs<ValueDecl>();
SourceLocation EllipsisLoc = readSourceLocation();
new (ToCapture) Capture(Loc, IsImplicit, Kind, Var, EllipsisLoc);
ToCapture++;
Expand Down
24 changes: 24 additions & 0 deletions clang/test/Modules/pr72828.cppm
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Test that we can handle capturing structured bindings.
//
// RUN: rm -fr %t
// RUN: mkdir %t
//
// RUN: %clang_cc1 -std=c++23 -triple %itanium_abi_triple \
// RUN: %s -emit-module-interface -o %t/m.pcm
// RUN: %clang_cc1 -std=c++23 -triple %itanium_abi_triple \
// RUN: -S -emit-llvm -disable-llvm-passes %t/m.pcm \
// RUN: -o - | FileCheck %s

export module m;

struct s {
int m;
};

void f() {
auto [x] = s();
[x] {};
}

// Check that we can generate the LLVM IR expectedly.
// CHECK: define{{.*}}@_ZGIW1m

0 comments on commit 649e811

Please sign in to comment.