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
23 lines
573 B
C++
23 lines
573 B
C++
// 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);
|
|
}
|
|
}
|