-
Notifications
You must be signed in to change notification settings - Fork 10.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[clang] Diagnose shadowing of lambda's template parameter by a capture
expr.prim.lambda.capture p5 says: If an identifier in a capture appears as the declarator-id of a parameter of the lambda-declarator's parameter-declaration-clause or as the name of a template parameter of the lambda-expression's template-parameter-list, the program is ill-formed. and also has the following example: ``` auto h = [y = 0]<typename y>(y) { return 0; }; ``` which now results in ``` error: declaration of 'y' shadows template parameter auto l1 = [y = 0]<typename y>(y) { return 0; }; ^ note: template parameter is declared here auto l1 = [y = 0]<typename y>(y) { return 0; }; ^ ``` Fixes #61105 Reviewed By: shafik, cor3ntin Differential Revision: https://reviews.llvm.org/D148712
- Loading branch information
Showing
4 changed files
with
52 additions
and
0 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
10 changes: 10 additions & 0 deletions
10
clang/test/CXX/expr/expr.prim/expr.prim.lambda/expr.prim.lambda.capture/p5.cpp
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,10 @@ | ||
// RUN: %clang_cc1 -std=c++20 -verify %s | ||
|
||
void f() { | ||
int x = 0; | ||
auto g = [x](int x) { return 0; }; // expected-error {{a lambda parameter cannot shadow an explicitly captured entity}} \ | ||
// expected-note {{variable 'x' is explicitly captured here}} | ||
auto h = [y = 0]<typename y>(y) { return 0; }; // expected-error {{declaration of 'y' shadows template parameter}} \ | ||
// expected-note {{template parameter is declared here}} | ||
|
||
} |
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