Edit: This now errors on godbolt (gcc, msvc) with non-empty initialization. There was some confusion because my msvc was erroring with empty initialization when godbolt wasn't (probably because my msvc is more recent).
#include <vector>
constexpr std::size_t f() {
constexpr std::vector<int> v{ 1 };
return 1;
}
int main() {
constexpr auto a = f();
}
With /std:c++latest
ConsoleApplication9.cpp(12,24): error C2131: expression did not evaluate to a constant ConsoleApplication9.cpp(12,24): message : (sub-)object points to memory which was heap allocated during constant evaluation
Edit: gcc warning with non-empty initialization explains the problem
error: 'std::vector(std::initializer_list{((const int*)(& const int [1]{1})), 1}, std::allocator())' is not a constant expression because it refers to a result of 'operator new' 195 | return static_cast<_Tp*>(::operator new(__n)); | ~~~~~~~~~~~~~~^~~~~