Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[clang] Correctly handle by-reference capture with an initializer tha…
…t is a pack expansion in lambdas. Ensure that the correct information whether an init-capture of a lambda is passed by reference or by copy. This information is already computed and has to be passed to the place where `NewInitCaptureType` is created. Before this fix it has been checked whether the VarDecl is a reference type. This doesn't work for packed expansions, as the information whether it is passed by reference or by copy is stored at the pattern of a `PackExpansionType` and not at the type itself. However, as the information has been already computed, we just have to pass it. Add tests that lambda captures with var decls which are reference types are created in the AST and a disgnotics test for pack expansions. Fixes #49266 Differential Revision: https://reviews.llvm.org/D139125
- Loading branch information
1 parent
7203a86
commit edbea62
Showing
5 changed files
with
56 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// RUN: %clang_cc1 -std=c++20 -Wno-unused-value -fsyntax-only -verify %s | ||
|
||
namespace GH49266 { | ||
struct X { | ||
X() = default; | ||
X(X const&) = delete; // expected-note {{'X' has been explicitly marked deleted here}} | ||
}; | ||
|
||
void take_by_copy(auto &...args) { | ||
[...args = args] {}(); // expected-error {{call to deleted constructor}} | ||
} | ||
|
||
void take_by_ref(auto &...args) { | ||
[&...args = args] {}(); // args is passed by reference and not copied. | ||
} | ||
|
||
void foo() { | ||
X x; | ||
take_by_copy(x); // expected-note {{in instantiation of function template specialization}} | ||
take_by_ref(x); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters