Skip to content

Clang error when using a constexpr variable as NTTP default value in lambda expression. #107048

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

Closed
ldalessa opened this issue Sep 3, 2024 · 4 comments · Fixed by #107073
Closed
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" constexpr Anything related to constant evaluation diverges-from:edg Does the clang frontend diverge from edg compiler lambda C++11 lambda expressions

Comments

@ldalessa
Copy link

ldalessa commented Sep 3, 2024

void foo()
{
    constexpr int x{};
    auto a = []<int=x>{};
}

Looks like a regression from 16 to 17, persists in 18 and current trunk.

https://godbolt.org/z/TErqq79ao

@github-actions github-actions bot added the clang Clang issues not falling into any other category label Sep 3, 2024
@EugeneZelenko EugeneZelenko added clang:frontend Language frontend issues, e.g. anything involving "Sema" lambda C++11 lambda expressions constexpr Anything related to constant evaluation and removed clang Clang issues not falling into any other category labels Sep 3, 2024
@llvmbot
Copy link
Member

llvmbot commented Sep 3, 2024

@llvm/issue-subscribers-clang-frontend

Author: Luke D'Alessandro (ldalessa)

```c++ void foo() { constexpr int x{}; auto a = []<int=x>{}; } ```

Looks like a regression from 16 to 17, persists in 18 and current trunk.

https://godbolt.org/z/TErqq79ao

@zyn0217
Copy link
Contributor

zyn0217 commented Sep 3, 2024

Now only EDG accepts it. https://godbolt.org/z/h58Ko1rce

@zyn0217 zyn0217 added the diverges-from:edg Does the clang frontend diverge from edg compiler label Sep 3, 2024
@zyn0217
Copy link
Contributor

zyn0217 commented Sep 3, 2024

Probably, this has been turned into ill-formed according to P2036R3:

Otherwise (if P either precedes E’s function parameter scope or is in E’s parameter-declaration-clause), the program is ill-formed.

And clues from P2579R0 could also prove this point:

Template Parameters

  int x;
  [x]<auto N = x> {}

This is made ill-formed by P2036 and the proposed mitigation. [...]

But what confuses me is that we don't appear to diagnose such lambdas containing explicit captures; instead, we just give errors on lambda with no captures. (Which is OP's example)

@cor3ntin Could you confirm?

@ldalessa
Copy link
Author

ldalessa commented Sep 3, 2024

I want to mention that the real use case I have is in a decltype() for the lambda. I’m not sure if this changes any of the standardese associated with it. I can post a more sophisticated use when I get back to my computer.

cor3ntin added a commit to cor3ntin/llvm-project that referenced this issue Sep 3, 2024
We only check that a default argument is a converted constant
expression when using the default argument.

However, when parsing a default argument, we need to make sure
to parse it as a constant expression such as not ODR-use variables.
(otherwise, we would try to capture default template arguments
of generic lambdas)

Fixes llvm#107048
cor3ntin added a commit that referenced this issue Sep 4, 2024
)

We only check that a default argument is a converted constant expression
when using the default argument.

However, when parsing a default argument, we need to make sure to parse
it as a constant expression such as not ODR-use variables. (otherwise,
we would try to capture default template arguments of generic lambdas)

Fixes #107048
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" constexpr Anything related to constant evaluation diverges-from:edg Does the clang frontend diverge from edg compiler lambda C++11 lambda expressions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants