https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92695
Bug ID: 92695 Summary: [10, 9] P1064R0 - virtual constexpr fails if object taken from array Product: gcc Version: 10.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: lutztonineubert at gmail dot com Target Milestone: --- The following code fails with: -> error: expression 'A::get' is not a constant expression Compiled with `-std=c++2a` under GCC-9.2 and GCC-trunk. It works under Clang-trunk. ``` struct A { constexpr virtual int get() = 0; }; struct B : A { constexpr int get() override { return 10; } }; struct Foo { B b[1] = {}; constexpr A * get_a() { // Seems to be the problem. return &(b[0]); } }; constexpr int get() { Foo f; return f.get_a()->get(); } constexpr auto a = get(); int main() { return a; } ``` The dereferencing of the array seems to be the problem. See online here: https://gcc.godbolt.org/z/ZSXAfb