Closed
Description
Consider this example code:
class Base {
public:
virtual ~Base() {}
};
constexpr int test() {
Base b;
return 0;
}
clang -std=c++20
complains:
<source>:8:8: error: variable of non-literal type 'Base' cannot be defined in a constexpr function before C++2b
Base b;
^
<source>:3:11: note: 'Base' is not literal because its destructor is not constexpr
virtual ~Base() {}
^
1 error generated.
However, using -std=c++2b
instead gives:
<source>:7:15: error: constexpr function never produces a constant expression [-Winvalid-constexpr]
constexpr int test() {
^
<source>:8:8: note: non-literal type 'Base' cannot be used in a constant expression
Base b;
^
1 error generated.