Both GCC and MSVC seem to allow defining constexpr accessor functions for non-const data members:
#include <random>
#include <iostream>
class Foo
{
int val;
public:
Foo(int v) : val(v) {}
constexpr int get_val() { return val; } // OK
};
int main()
{
std::random_device rd;
Foo foo((int)rd());
std::cout << foo.get_val(); // works
}
Is this nonstandard behavior from MSVC and GCC or does the standard actually allow this?