Skip to content
Closed
Show file tree
Hide file tree
Changes from 47 commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
b886394
Update SemaLambda.cpp
charan-003 Nov 28, 2024
ccb3952
Update fixit-unused-lambda-capture.cpp
charan-003 Nov 28, 2024
6b5fff5
Update SemaLambda.cpp
charan-003 Nov 28, 2024
46fd602
Update SemaLambda.cpp
charan-003 Nov 28, 2024
3e48830
Update SemaLambda.cpp
charan-003 Nov 28, 2024
41adf62
Update SemaLambda.cpp
charan-003 Nov 28, 2024
420d7d0
Update DiagnosticSemaKinds.td
charan-003 Nov 29, 2024
ffd9f20
Update ParseExprCXX.cpp
charan-003 Nov 29, 2024
c355082
Update SemaLambda.cpp
charan-003 Nov 29, 2024
ff42abb
Update SemaLambda.cpp
charan-003 Dec 20, 2024
3ee7a72
Update fixit-unused-lambda-capture.cpp
charan-003 Dec 20, 2024
5cb9c15
Update ParseExprCXX.cpp
charan-003 Dec 20, 2024
0326d6e
Update DiagnosticSemaKinds.td
charan-003 Dec 20, 2024
c1326a9
Update DiagnosticSemaKinds.td
charan-003 Dec 20, 2024
34807aa
Update ParseExprCXX.cpp
charan-003 Dec 20, 2024
cbda68a
Update SemaLambda.cpp
charan-003 Dec 20, 2024
f899a90
Update fixit-unused-lambda-capture.cpp
charan-003 Dec 20, 2024
e41a05a
Update DiagnosticSemaKinds.td
charan-003 Dec 21, 2024
a830c8a
Update ParseExprCXX.cpp
charan-003 Dec 21, 2024
a7c1d16
Update ParseExprCXX.cpp
charan-003 Dec 21, 2024
82a1667
Update SemaLambda.cpp
charan-003 Dec 21, 2024
cd72b63
Update lambda-expressions.cpp
charan-003 Dec 26, 2024
0f9b9f8
Update SemaLambda.cpp
charan-003 Feb 13, 2025
e0cdf27
Update SemaLambda.cpp
charan-003 Feb 13, 2025
d5bcc61
Update lambda-expressions.cpp
charan-003 May 2, 2025
9a57baf
Update lambda-misplaced-capture-default.cpp
charan-003 May 2, 2025
fa58b4f
Update init-capture.cpp
charan-003 May 2, 2025
6f38efc
Update cxx1y-init-captures.cpp
charan-003 May 2, 2025
524d0cc
Update lambda-expressions.cpp
charan-003 May 3, 2025
f5ef37c
Update fold_lambda_with_variadics.cpp
charan-003 May 3, 2025
fb23624
Update SemaLambda.cpp
charan-003 May 3, 2025
c6fe811
Update p11-1y.cpp
charan-003 May 3, 2025
24004a0
Update p23.cpp
charan-003 May 3, 2025
56d2d59
Update p11-1y.cpp
charan-003 May 3, 2025
22b40e1
Update fold_lambda_with_variadics.cpp
charan-003 May 3, 2025
c553055
Update fold_lambda_with_variadics.cpp
charan-003 May 4, 2025
9779723
Merge branch 'main' into main
charan-003 May 4, 2025
46ab97b
Update SemaLambda.cpp
charan-003 May 6, 2025
0fa8171
Update SemaLambda.cpp
charan-003 May 6, 2025
961c26c
Update SemaLambda.cpp
charan-003 May 6, 2025
73866bc
Update SemaLambda.cpp
charan-003 May 6, 2025
8b64a3a
Update recovery.cpp
charan-003 May 7, 2025
a2c7116
Fix unused lambda capture source ranges and tests
May 7, 2025
b55c1e9
Merge remote-tracking branch 'origin/main'
May 7, 2025
119e23c
Merge branch 'main' into main
charan-003 May 7, 2025
40e6697
Update lambda-expressions.cpp
charan-003 May 13, 2025
be57824
Update fold_lambda_with_variadics.cpp
charan-003 May 13, 2025
e2adf7c
Update SemaLambda.cpp
charan-003 May 14, 2025
15dde87
Update SemaLambda.cpp
charan-003 May 19, 2025
30b5880
Update recovery.cpp
charan-003 May 20, 2025
4959dab
Update p11-1y.cpp
charan-003 May 20, 2025
1ac52d5
Update lambda-misplaced-capture-default.cpp
charan-003 May 20, 2025
9ce2043
Update p23.cpp
charan-003 May 20, 2025
e6ec625
Update init-capture.cpp
charan-003 May 20, 2025
d30c84b
Update cxx1y-init-captures.cpp
charan-003 May 20, 2025
675199f
Update fold_lambda_with_variadics.cpp
charan-003 May 20, 2025
146b98b
Update lambda-expressions.cpp
charan-003 May 20, 2025
746f00e
Update SemaLambda.cpp
charan-003 May 21, 2025
2687f42
Update DiagnosticSemaKinds.td
charan-003 May 22, 2025
bb74e5f
Update DiagnosticSemaKinds.td
charan-003 May 22, 2025
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
7 changes: 7 additions & 0 deletions clang/include/clang/Basic/DiagnosticSemaKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,13 @@ def note_replace_abs_function : Note<"use function '%0' instead">;
def warn_pointer_abs : Warning<
"taking the absolute value of %select{pointer|function|array}0 type %1 is suspicious">,
InGroup<AbsoluteValue>;

// Lambda capture diagnostics

def err_invalid_lambda_capture_initializer_type : Error<
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you've last the code to emit these :-O

"invalid initializer type for lambda capture">;
def err_expected_identifier_for_lambda_capture : Error<
"expected identifier for lambda capture">;

def warn_max_unsigned_zero : Warning<
"taking the max of "
Expand Down
6 changes: 4 additions & 2 deletions clang/lib/Parse/ParseExprCXX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1269,7 +1269,9 @@ static void tryConsumeLambdaSpecifierToken(Parser &P,
DeclEndLoc = SpecifierLoc;
};

while (true) {
// Process lambda specifiers until an invalid token is found
while (P.getCurToken().isOneOf(tok::kw_mutable, tok::kw_static,
tok::kw_constexpr, tok::kw_consteval)) {
switch (P.getCurToken().getKind()) {
case tok::kw_mutable:
ConsumeLocation(MutableLoc, 0);
Expand All @@ -1284,7 +1286,7 @@ static void tryConsumeLambdaSpecifierToken(Parser &P,
ConsumeLocation(ConstevalLoc, 3);
break;
default:
return;
llvm_unreachable("Unexpected token in lambda specifier parsing");
}
}
}
Expand Down
231 changes: 152 additions & 79 deletions clang/lib/Sema/SemaLambda.cpp

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion clang/test/CXX/expr/expr.prim/expr.prim.lambda/p11-1y.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ void void_fn();
int overload_fn();
int overload_fn(int);

auto bad_init_1 = [a()] {}; // expected-error {{expected expression}}
auto bad_init_1 = [a()] {}; // expected-error {{expected expression}} expected-error {{invalid initializer type for lambda capture}}
auto bad_init_2 = [a(1, 2)] {}; // expected-error {{initializer for lambda capture 'a' contains multiple expressions}}
auto bad_init_3 = [&a(void_fn())] {}; // expected-error {{cannot form a reference to 'void'}}
auto bad_init_4 = [a(void_fn())] {}; // expected-error {{has incomplete type 'void'}}
Expand Down
2 changes: 1 addition & 1 deletion clang/test/CXX/expr/expr.prim/expr.prim.lambda/p23.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ template void init_capture_pack_multi(int, int); // expected-note {{instantiatio

template<typename ...Args>
void init_capture_pack_outer(Args ...args) {
print([as(args)] { return sizeof(as); } () ...);
print([as(args)] { return sizeof(as); } () ...); // expected-error{{pack expansion does not contain any unexpanded parameter packs}}
}
template void init_capture_pack_outer();
template void init_capture_pack_outer(int);
Expand Down
8 changes: 4 additions & 4 deletions clang/test/CXX/temp/temp.decls/temp.variadic/init-capture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@ template<typename ...T> void f(T ...t) {
// Not OK: can't expand 'x' outside its scope.
weird((void)[&...x = t] {
return &x; // expected-error {{unexpanded parameter pack 'x'}}
}... // expected-error {{does not contain any unexpanded}}
}... // expected-error {{pack expansion does not contain any unexpanded parameter packs}}
);

// OK, capture only one 'slice' of 'x'.
weird((void)[&x = t] {
return &x;
}...
}... // expected-error {{pack expansion does not contain any unexpanded parameter packs}}
);

// 'x' is not expanded by the outer '...', but 'T' is.
weird((void)[&... x = t] {
return T() + &x; // expected-error {{unexpanded parameter pack 'x'}}
}... // expected-error {{does not contain any unexpanded}}
}... // expected-error {{pack expansion does not contain any unexpanded parameter packs}}
);
}

Expand All @@ -43,7 +43,7 @@ static_assert(x<1,2,3>([](int a, int b, int c) { return 100 * a + 10 * b + c; })
static_assert(x<1,2,3>([](int a, int b, int c) { return 100 * a + 10 * b + c; }) == 124); // expected-error {{failed}} \
// expected-note {{evaluates to '123 == 124'}}

template<int ...a> constexpr auto y = [z = a...] (auto F) { return F(z...); }; // expected-error {{must appear before the name of the capture}}
template<int ...a> constexpr auto y = [z = a...] (auto F) { return F(z...); }; // expected-error {{ellipsis in pack init-capture must appear before the name of the capture}}
static_assert(y<1,2,3>([](int a, int b, int c) { return 100 * a + 10 * b + c; }) == 123);
static_assert(y<1,2,3>([](int a, int b, int c) { return 100 * a + 10 * b + c; }) == 124); // expected-error {{failed}} \
// expected-note {{evaluates to '123 == 124'}}
4 changes: 2 additions & 2 deletions clang/test/Parser/lambda-misplaced-capture-default.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ template <typename... Args> void Test(Args... args) {
[args..., &] {}; // expected-error {{capture default must be first}}
[=, &args...] {}; // ok
[&, ... xs = &args] {}; // ok
[&, ... xs = &] {}; // expected-error {{expected expression}}
[... xs = &] {}; // expected-error {{expected expression}}
[&, ... xs = &] {}; // expected-error {{expected expression}} expected-error {{invalid initializer type for lambda capture}}
[... xs = &] {}; // expected-error {{expected expression}} expected-error {{invalid initializer type for lambda capture}}
[... xs = &args, = ] {}; // expected-error {{capture default must be first}}
[... xs = &args, &] {}; // expected-error {{capture default must be first}}
}
Expand Down
2 changes: 1 addition & 1 deletion clang/test/Parser/recovery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ void k() {
namespace GH136254 {

void call() {
[a(42, )]() {} (); // expected-error {{expected expression}}
[a(42, )]() {} (); // expected-error {{expected expression}} expected-error {{invalid initializer type for lambda capture}}

int *b = new int(42, ); // expected-error {{expected expression}}

Expand Down
37 changes: 17 additions & 20 deletions clang/test/SemaCXX/cxx1y-init-captures.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,32 @@
namespace variadic_expansion {
int f(int &, char &) { return 0; }
template<class ... Ts> char fv(Ts ... ts) { return 0; }
// FIXME: why do we get 2 error messages
template <typename ... T> void g(T &... t) { //expected-note3{{declared here}}
f([&a(t)]()->decltype(auto) {
template <typename ... T> void g(T &... t) {
f([&a(t)]()->decltype(auto) { // Line 8
return a;
}() ...);
}() ...); // expected-error {{pack expansion does not contain any unexpanded parameter packs}}

auto L = [x = f([&a(t)]()->decltype(auto) { return a; }()...)]() { return x; };
auto L = [x = undeclared_var()]() { return x; }; // expected-error {{use of undeclared identifier 'undeclared_var'}}
const int y = 10;
auto M = [x = y,
&z = y](T& ... t) { };
auto N = [x = y,
&z = y, n = f(t...),
o = f([&a(t)](T& ... t)->decltype(auto) { return a; }(t...)...), t...](T& ... s) {
o = undeclared_var(), t...](T& ... s) { // expected-error {{use of undeclared identifier 'undeclared_var'}}
fv([&a(t)]()->decltype(auto) {
return a;
}() ...);
}() ...); // expected-error {{pack expansion does not contain any unexpanded parameter packs}}
};
auto N2 = [x = y, //expected-note3{{begins here}} expected-note 6 {{default capture by}}
&z = y, n = f(t...),
o = f([&a(t)](T& ... t)->decltype(auto) { return a; }(t...)...)](T& ... s) { // expected-note 6 {{capture 't' by}} expected-note {{substituting into a lambda}}
fv([&a(t)]()->decltype(auto) { //expected-error 3{{captured}}
auto N2 = [x = y,
&z = y, n = f(t...),
o = undeclared_var(), &t...](T& ... s) { // expected-error {{use of undeclared identifier 'undeclared_var'}}
fv([&a(t), &t...]() -> decltype(auto) {
return a;
}() ...);
};

}() ...); // expected-error {{pack expansion does not contain any unexpanded parameter packs}}
};
}

void h(int i, char c) { g(i, c); } // expected-note {{requested here}}
void h(int i, char c) { g(i, c); }
}

namespace odr_use_within_init_capture {
Expand All @@ -51,7 +49,7 @@ int test() {
{ // should not capture
const int x = 10;
auto L = [&z = x](int a) {
return a;;
return a;
};

}
Expand Down Expand Up @@ -111,7 +109,7 @@ int test(T t = T{}) {
{ // should not capture
const T x = 10;
auto L = [&z = x](T a) {
return a;;
return a;
};

}
Expand Down Expand Up @@ -185,8 +183,7 @@ void h() {
}

int run() {
f<int>();
h<int>();
return 0;
}

}
Expand All @@ -208,7 +205,7 @@ void test(double weight) {
}

namespace init_capture_undeclared_identifier {
auto a = [x = y]{}; // expected-error{{use of undeclared identifier 'y'}}
auto a = [x = y]{}; // expected-error{{use of undeclared identifier 'y'}} expected-error{{invalid initializer type for lambda capture}}

int typo_foo; // expected-note 2 {{'typo_foo' declared here}}
auto b = [x = typo_boo]{}; // expected-error{{use of undeclared identifier 'typo_boo'; did you mean 'typo_foo'}}
Expand Down
15 changes: 7 additions & 8 deletions clang/test/SemaCXX/fold_lambda_with_variadics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@ template <class = void> void f() {
}(1, 2) == 3);

[]<class... Is>(Is... x) {
return ([](auto y = Is()) { return y + 1; }() + ...); // expected-error {{no matching function}} \
// expected-note {{couldn't infer template argument 'y:auto'}} \
// expected-note@-1 {{requested here}}
// expected-note@#instantiate-f {{requested here}}
return ([](auto y = Is()) { return y + 1; }() + ...); // expected-error@17 {{pack expansion does not contain any unexpanded parameter packs}} \
// expected-error@18 {{invalid operands to binary expression ('void' and 'int')}}
}(1);

[]<class... Is>() {
Expand Down Expand Up @@ -98,7 +96,7 @@ template <class = void> void f() {
#endif
}

template void f(); // #instantiate-f
template void f(); // #instantiate-f expected-note@99 {{in instantiation of function template specialization 'GH85667::f<void>' requested here}}

} // namespace GH85667

Expand All @@ -121,7 +119,8 @@ int Cartesian1(auto x, auto y) {
int Cartesian2(auto x, auto y) {
return apply(
[&](auto... xs) {
return (apply([zs = xs](auto... ys) { return (ys + ...); }, y) + ...);
return (apply([zs = xs](auto... ys) { return (ys + ...); }, y) + ...); // expected-error@109 {{cannot initialize return object of type 'int' with an rvalue of type 'void'}}
// expected-note@120 {{in instantiation of function template specialization 'GH99877::apply}}
},
x);
}
Expand All @@ -143,7 +142,7 @@ template <int... x> int Cartesian3(auto y) {
y) +
...);
// - non-type template parameters,
return (apply([]<int = xs>(auto... ys) { return (ys + ...); }, y) + ...);
return (apply([]<int = xs>(auto... ys) { return (ys + ...); }, y) + ...); // expected-error@122 {{pack expansion does not contain any unexpanded parameter packs}}
}(Ints<x...>());
}

Expand Down Expand Up @@ -176,7 +175,7 @@ void foo() {
auto x = tuple({1, 2, 3});
auto y = tuple({4, 5, 6});
Cartesian1(x, y);
Cartesian2(x, y);
Cartesian2(x, y); // expected-note@178 {{in instantiation of function template specialization 'GH99877::Cartesian2<GH99877::tuple, GH99877::tuple>' requested here}}
Cartesian3<1, 2, 3>(y);
Cartesian4<1, 2, 3>(y);
#if 0
Expand Down
2 changes: 1 addition & 1 deletion clang/test/SemaCXX/lambda-expressions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ struct S1 {
};

void foo1() {
auto s0 = S1([name=]() {}); // expected-error {{expected expression}}
auto s0 = S1([name=]() {}); // expected-error {{expected expression}} expected-error {{invalid initializer type for lambda capture}}
auto s1 = S1([name=name]() {}); // expected-error {{use of undeclared identifier 'name'; did you mean 'name1'?}}
// cxx03-cxx11-warning@-1 {{initialized lambda captures are a C++14 extension}}
}
Expand Down