I was reading this answer about constexpr vector
in C++20, where the poster gave this code
constexpr int f() {
std::vector<int> v = {1, 2, 3};
return v.size();
}
static_assert(f() == 3);
which he asserts is correct under C++20. He also gave this successfully compiled (in MSVC v19) Godbolt snippet.
However as I change the compiler to gcc 10 (which is supposed to support C++20 and constexpr container), compiler emits error messages complaining roughly about vector<int>
being non-literal type because it does not have constexpr
destructor.
This kind of compile error persist to gcc 11, though. In gcc 12.1, it compiles successfully.
Having browsed the gcc 12.1 changes history, I found out this seemingly relevant change
Several C++23 features have been implemented
My questions are:
vector
do have aconstexpr
destructor since C++20 right? (see cppref) Why does gcc before 12 complains as not?Whether the above code is strictly legal under C++20? Which one of MSVC or gcc is not standard conformant?
TBH I'm not in the stage to fully understand the proposal. Can you explains what it is about? Which problems does it try to solve?