C++20 Constexpr virtual not compiling

Shouldn't this compile under C++20 on the latest versions of GCC and Clang?

I know that it is not yet supported on Visual Studio C++ compiler.

However, according to this list: https://en.cppreference.com/w/cpp/compiler_support it should have worked with no problems on GCC and Clang.

#include <iostream>

struct Base {
    constexpr virtual ~Base() noexcept = default;

    [[nodiscard]] constexpr virtual int
    get_value() const noexcept = 0;
};

struct Derived
    : Base {
    [[nodiscard]] constexpr virtual int
    get_value() const noexcept override {
        return 5;
    }
};

int
main() {

    constexpr Derived a;
    constexpr Base const & b = a;
    constexpr auto c = b.get_value();

    std::cout << c << '\n';

    return 0;
}


Read more here: https://stackoverflow.com/questions/64414308/c20-constexpr-virtual-not-compiling

Content Attribution

This content was originally published by João Pires at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: