Skip to content

[clang][bytecode] Call to consteval function is not a constant expression when calling a virtual method #165234

@BobIsOnFire

Description

@BobIsOnFire
struct A {
    constexpr virtual void call(int) = 0;

    constexpr void call2() { call(0); }
};

struct B : A {
    constexpr void call(int) override {}
};

consteval void check() {
    B b;
    b.call2();
}

int main() { check(); }
<source>:16:14: error: call to consteval function 'check' is not a constant expression
   16 | int main() { check(); }
      |              ^
<source>:4:30: note: pure virtual function 'A::call' called
    4 |     constexpr void call2() { call(0); }
      |                              ^
<source>:13:5: note: in call to 'b.call2()'
   13 |     b.call2();
      |     ^~~~~~~~~
<source>:16:14: note: in call to 'check()'
   16 | int main() { check(); }
      |              ^~~~~~~
<source>:2:28: note: declared here
    2 |     constexpr virtual void call(int) = 0;
      |                            ^
1 error generated.
Compiler returned: 1

https://godbolt.org/z/h4hdW9ars

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:bytecodeIssues for the clang bytecode constexpr interpreter

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions