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

call to consteval in immediate invocation context fails #51182

Closed
llvmbot opened this issue Sep 14, 2021 · 3 comments
Closed

call to consteval in immediate invocation context fails #51182

llvmbot opened this issue Sep 14, 2021 · 3 comments
Assignees
Labels
bugzilla Issues migrated from bugzilla c++20 clang:frontend Language frontend issues, e.g. anything involving "Sema" confirmed Verified by a second party consteval C++20 consteval

Comments

@llvmbot
Copy link
Member

llvmbot commented Sep 14, 2021

Bugzilla Link 51840
Version trunk
OS Linux
Reporter LLVM Bugzilla Contributor
CC @dwblaikie,@zygoloid

Extended Description

Reduced from https://stackoverflow.com/questions/69166564

The following code fails on clang >= 11.0 (including trunk)

consteval int f(int) { return 1; }

template
consteval bool g(T a)
{
int n = f(a); // error here
return true;
}

static_assert(g(2));


with
error: call to consteval function 'f' is not a constant expression
note: read of non-const variable 'a' is not allowed in a constant expression

This seems incorrect. The evaluation of f is in an immediate context, i.e. inside g so f(a) should be a constant expression. Also, the error only appears if g is a template, and if the result of f(a) is stored in a local variable. GCC accepts the code.

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 11, 2021
@Izaron
Copy link
Member

Izaron commented Feb 12, 2022

Thank you for the issue! I proposed a fix here - https://reviews.llvm.org/D119651

@EugeneZelenko EugeneZelenko added the clang:frontend Language frontend issues, e.g. anything involving "Sema" label Feb 12, 2022
@llvmbot
Copy link
Member Author

llvmbot commented Feb 12, 2022

@llvm/issue-subscribers-clang-frontend

@usx95
Copy link
Contributor

usx95 commented Aug 25, 2022

Alternative proposal: https://reviews.llvm.org/D132659

@usx95 usx95 closed this as completed in 4a043c6 Aug 26, 2022
Repository owner moved this from In Progress to Done in Core C++20 in Clang Aug 26, 2022
Repository owner moved this from In Progress to Done in C++ 20 in Clang Aug 26, 2022
BertalanD added a commit to BertalanD/serenity that referenced this issue May 21, 2024
Format string checking was disabled in Clang-based builds due to a
compiler bug: llvm/llvm-project#51182. Now
that the requirement has been raised to Clang 17, that is no longer
necessary.

This has been tested to work correctly with Apple Clang 15.0.0 (which is
the *least modern* supported compiler), as well as CLion 2024.1's
bundled Clangd.
BertalanD added a commit to BertalanD/serenity that referenced this issue May 29, 2024
Format string checking was disabled in Clang-based builds due to a
compiler bug: llvm/llvm-project#51182. Now
that the requirement has been raised to Clang 17, that is no longer
necessary.

This has been tested to work correctly with Apple Clang 15.0.0 (which is
the *least modern* supported compiler), as well as CLion 2024.1's
bundled Clangd.
ADKaster pushed a commit to SerenityOS/serenity that referenced this issue May 29, 2024
Format string checking was disabled in Clang-based builds due to a
compiler bug: llvm/llvm-project#51182. Now
that the requirement has been raised to Clang 17, that is no longer
necessary.

This has been tested to work correctly with Apple Clang 15.0.0 (which is
the *least modern* supported compiler), as well as CLion 2024.1's
bundled Clangd.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla c++20 clang:frontend Language frontend issues, e.g. anything involving "Sema" confirmed Verified by a second party consteval C++20 consteval
Projects
Status: Done
Development

No branches or pull requests

5 participants