Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

capture local constexpr variable #59959

Closed
ordinary-github-user opened this issue Jan 12, 2023 · 5 comments
Closed

capture local constexpr variable #59959

ordinary-github-user opened this issue Jan 12, 2023 · 5 comments
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" duplicate Resolved as duplicate

Comments

@ordinary-github-user
Copy link

ordinary-github-user commented Jan 12, 2023

int main()
{
    constexpr int a{};
    []{return a;}();//compile yes
    []{a;}();//compile no
}

Diagnostic:

<source>:5:8: error: variable 'a' cannot be implicitly captured in a lambda with no capture-default specified
    5 |     []{a;}();//compile no
      |        ^
<source>:3:19: note: 'a' declared here
    3 |     constexpr int a{};
      |                   ^
<source>:5:5: note: lambda expression begins here
    5 |     []{a;}();//compile no
      |     ^
<source>:5:6: note: capture 'a' by value
    5 |     []{a;}();//compile no
      |      ^
      |      a
<source>:5:6: note: capture 'a' by reference
    5 |     []{a;}();//compile no
      |      ^
      |      &a
<source>:5:6: note: default capture by value
    5 |     []{a;}();//compile no
      |      ^
      |      =
<source>:5:6: note: default capture by reference
    5 |     []{a;}();//compile no
      |      ^
      |      &
<source>:5:8: warning: expression result unused [-Wunused-value]
    5 |     []{a;}();//compile no
      |        ^
1 warning and 1 error generated.
Compiler returned: 1
@EugeneZelenko EugeneZelenko added clang:frontend Language frontend issues, e.g. anything involving "Sema" and removed new issue labels Jan 12, 2023
@llvmbot
Copy link
Member

llvmbot commented Jan 12, 2023

@llvm/issue-subscribers-clang-frontend

@shafik
Copy link
Collaborator

shafik commented Jan 13, 2023

I believe this is a clang bug, a is implicitly captured and not odr-used as far as I can tell from basic.def.odr p5 because it is a discarded-value expression.

CC @cor3ntin

@shafik
Copy link
Collaborator

shafik commented Jan 13, 2023

May be related to: #55617

@shafik
Copy link
Collaborator

shafik commented Jan 13, 2023

This looks like a duplicate of: #34603

The second test case from David is basically identical.

@shafik
Copy link
Collaborator

shafik commented Jan 13, 2023

Also see: #26001

@shafik shafik added the duplicate Resolved as duplicate label Jul 11, 2023
@shafik shafik closed this as not planned Won't fix, can't repro, duplicate, stale Jul 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" duplicate Resolved as duplicate
Projects
None yet
Development

No branches or pull requests

4 participants