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

lambda's operator() is non-constexpr function #97958

Open
Fedr opened this issue Jul 7, 2024 · 3 comments
Open

lambda's operator() is non-constexpr function #97958

Fedr opened this issue Jul 7, 2024 · 3 comments
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" lambda C++11 lambda expressions

Comments

@Fedr
Copy link

Fedr commented Jul 7, 2024

This program

static_assert(
    []<int I=0>() -> decltype([]{ return true; })
    { return {}; }()());

is accepted in GCC, MSVC and Clang 17, but Clang 18 complains:

error: static assertion expression is not an integral constant expression
    2 |     []<int I=0>() -> decltype([]{ return true; })
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    3 |     { return {}; }()());
      |     ~~~~~~~~~~~~~~~~~~
<source>:2:5: note: non-constexpr function 'operator()' cannot be used in a constant expression
<source>:2:31: note: declared here
    2 |     []<int I=0>() -> decltype([]{ return true; })

Online demo: https://gcc.godbolt.org/z/nW74e4q9v

It is a modified example from https://stackoverflow.com/q/77431308/7325599

@EugeneZelenko EugeneZelenko added clang:frontend Language frontend issues, e.g. anything involving "Sema" lambda C++11 lambda expressions and removed new issue labels Jul 7, 2024
@llvmbot
Copy link
Member

llvmbot commented Jul 7, 2024

@llvm/issue-subscribers-clang-frontend

Author: Fedor Chelnokov (Fedr)

This program ``` static_assert( []<int I=0>() -> decltype([]{ return true; }) { return {}; }()()); ``` is accepted in GCC, MSVC and Clang 17, but Clang 18 complains: ``` error: static assertion expression is not an integral constant expression 2 | []<int I=0>() -> decltype([]{ return true; }) | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 3 | { return {}; }()()); | ~~~~~~~~~~~~~~~~~~ <source>:2:5: note: non-constexpr function 'operator()' cannot be used in a constant expression <source>:2:31: note: declared here 2 | []<int I=0>() -> decltype([]{ return true; }) ``` Online demo: https://gcc.godbolt.org/z/nW74e4q9v

It is a modified example from https://stackoverflow.com/q/77431308/7325599

@MitalAshok
Copy link
Contributor

git bisect points to 890f11d

@tbaederr
Copy link
Contributor

tbaederr commented Jul 8, 2024

CC @cor3ntin

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" lambda C++11 lambda expressions
Projects
None yet
Development

No branches or pull requests

5 participants