Skip to content

[Clang] Capturing attribute argument on lambda throws error #59549

Closed
@elizabethandrews

Description

void foo () {
  constexpr int i = 2;

  [&]() {
    [=]() [[clang::annotate_type("test", i)]]{};
  };
}
<source>:5:42: error: variable 'i' cannot be implicitly captured in a lambda with no capture-default specified
    [=]() [[clang::annotate_type("test", i)]]{};
                                         ^
<source>:2:17: note: 'i' declared here
  constexpr int i = 2;

Moving the captured variable to outer lambda scope fixes the error - https://godbolt.org/z/sPWx9aK5T
Capturing variable inside lambda body (instead of attribute argument) works - https://godbolt.org/z/z79jM9GMc

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

clang:frontendLanguage frontend issues, e.g. anything involving "Sema"

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions