llvm-project/clang/test/SemaCXX/lambda-invalid-capture.cpp
Nathan James cb559c8d5e
[Sema] Add some basic lambda capture fix-its
Adds fix-its when users forget to explicitly capture variables or this in lambdas

Addresses https://github.com/clangd/clangd/issues/697

Reviewed By: kbobyrev

Differential Revision: https://reviews.llvm.org/D96975
2021-03-11 13:46:25 +00:00

26 lines
688 B
C++

// RUN: %clang_cc1 -fsyntax-only -verify %s
// Don't crash.
struct g {
j; // expected-error {{C++ requires a type specifier for all declarations}}
};
void captures_invalid_type() {
g child;
auto q = [child]{};
const int n = sizeof(q);
}
void captures_invalid_array_type() {
g child[100];
auto q = [child]{};
const int n = sizeof(q);
}
int pr43080(int i) { // expected-note {{declared here}}
return [] { // expected-note {{begins here}} expected-note 2 {{capture 'i' by}} expected-note 2 {{default capture by}}
return sizeof i <
i; // expected-error {{variable 'i' cannot be implicitly captured in a lambda with no capture-default specified}}
}();
}