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

Array parameter cannot be used in nested consteval function call #57096

Closed
BertalanD opened this issue Aug 11, 2022 · 4 comments
Closed

Array parameter cannot be used in nested consteval function call #57096

BertalanD opened this issue Aug 11, 2022 · 4 comments
Labels
c++20 clang:frontend Language frontend issues, e.g. anything involving "Sema" duplicate Resolved as duplicate

Comments

@BertalanD
Copy link
Member

BertalanD commented Aug 11, 2022

Godbolt link

The following snippet does not compile with Clang (trunk), but does with MSVC and GCC:

template<unsigned int N>
consteval int inner(char const (&str)[N]) {
    return str[0];
}

template<unsigned int N>
consteval int func(char const (&str)[N]) {
    auto val = inner(str);
    return val;
}

auto var = func("test");
<source>:8:16: error: call to consteval function 'inner<5U>' is not a constant expression
    auto val = inner(str);
               ^
<source>:12:12: note: in instantiation of function template specialization 'func<5U>' requested here
auto var = func("test");
           ^
<source>:8:22: note: function parameter 'str' with unknown value cannot be used in a constant expression
    auto val = inner(str);
                     ^
<source>:7:33: note: declared here
consteval int func(char const (&str)[N]) {

The issue can be worked around by making inner constexpr instead of consteval.

@llvmbot
Copy link
Member

llvmbot commented Aug 11, 2022

@llvm/issue-subscribers-c-20

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

llvmbot commented Aug 11, 2022

@llvm/issue-subscribers-clang-frontend

@BertalanD BertalanD changed the title consteval function's argument cannot be used in call to another consteval function Array parameter cannot be used in nested consteval function call Aug 11, 2022
@usx95
Copy link
Contributor

usx95 commented Aug 20, 2022

Thanks for the report. Looks like the same issue of #51182

@usx95
Copy link
Contributor

usx95 commented Aug 20, 2022

Duplicate of #51182

@usx95 usx95 marked this as a duplicate of #51182 Aug 20, 2022
@usx95 usx95 closed this as not planned Won't fix, can't repro, duplicate, stale Aug 20, 2022
@EugeneZelenko EugeneZelenko added the duplicate Resolved as duplicate label Aug 20, 2022
@usx95 usx95 moved this to Done in C++ 20 in Clang Aug 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++20 clang:frontend Language frontend issues, e.g. anything involving "Sema" duplicate Resolved as duplicate
Projects
Status: Done
Development

No branches or pull requests

4 participants