Skip to content

clang not diagnosing generic lambda with identifier in capture matching declarator-id of template parameter  #61105

@shafik

Description

@shafik

Given the following:

void f() {
  auto h = [y = 0]<typename y>(y) { return 0; };
}

clang should diagnose this since it is ill-formed, we can see this from expr.prim.lambda.capture p5 which 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:

void f() {
  int x = 0;
  auto g = [x](int x) { return 0; };    // error: parameter and [capture](https://eel.is/c++draft/expr.prim.lambda#nt:capture) have the same name
  auto h = [y = 0]<typename y>(y) { return 0; };    // error: template parameter and [capture](https://eel.is/c++draft/expr.prim.lambda#nt:capture)
                                                    // have the same name
}

Metadata

Metadata

Assignees

Labels

accepts-invalidclang:frontendLanguage frontend issues, e.g. anything involving "Sema"confirmedVerified by a second party

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions