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 function in member initializer cause compilation error #118000

Open
finomen opened this issue Nov 28, 2024 · 2 comments · May be fixed by #124426
Open

Call to consteval function in member initializer cause compilation error #118000

finomen opened this issue Nov 28, 2024 · 2 comments · May be fixed by #124426
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" confirmed Verified by a second party consteval C++20 consteval

Comments

@finomen
Copy link

finomen commented Nov 28, 2024

If consteval function called in method initializer and this class used in both consteval and not consteval functions, compilation fails with

<source>:4:17: error: cannot take address of consteval function 'baz' outside of an immediate invocation
    int mSize = baz();
consteval int baz() { return 0;}

struct S {
    int mSize = baz();
};

consteval void bar() {
    S s;
}

void foo() {
    S s;
}

This bug is present in 16.x.x and >=18.0.0. (https://godbolt.org/z/o6EnWvvW7)

Issue was introduced in ca61961
After it was fixed in 4676885
And happens again after baf6bd3

@EugeneZelenko EugeneZelenko added clang:frontend Language frontend issues, e.g. anything involving "Sema" confirmed Verified by a second party consteval C++20 consteval and removed new issue labels Nov 28, 2024
@llvmbot
Copy link
Member

llvmbot commented Nov 28, 2024

@llvm/issue-subscribers-clang-frontend

Author: Nikolai Filchenko (finomen)

If consteval function called in method initializer and this class used in both consteval and not consteval functions, compilation fails with ``` <source>:4:17: error: cannot take address of consteval function 'baz' outside of an immediate invocation int mSize = baz(); ```
consteval int baz() { return 0;}

struct S {
    int mSize = baz();
};

consteval void bar() {
    S s;
}

void foo() {
    S s;
}

This bug is present in 16.x.x and >=18.0.0. (https://godbolt.org/z/o6EnWvvW7)

Issue was introduced in ca61961
After it was fixed in 4676885
And happens again after baf6bd3

@tbaederr
Copy link
Contributor

CC @cor3ntin

cor3ntin added a commit to cor3ntin/llvm-project that referenced this issue Jan 25, 2025
As we create defaul constructors lazily, we should not inherit
from the parent evaluation context.
However, we need to make an exception for lambdas (in particular
their conversion operators, which are also implicitly defined).

As a drive-by, we introduce a generic way to query whether a function
is a member of a lambda.

This fixes a regression introduced by baf6bd3.

Fixes llvm#118000
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" confirmed Verified by a second party consteval C++20 consteval
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants