Why are member functions returning non-static data members not core constant expressions?

Viewed 117

Consider the following example: (Demo)

struct S {
    static bool const x = true;
    const bool y = true;
    constexpr bool f() const { return x; }
    constexpr bool g() const { return y; }
};

int main() {

    const S s{};
    static_assert(s.f()); // OK
    static_assert(s.g()); // error
}

g++trunk gives the following errors:

error: non-constant condition for static assertion static_assert(s.g());
                                                                  
error: the value of 's' is not usable in a constant expression

note: 's' was not declared 'constexpr'

Why s.f() is core constant expression while s.g() is not?

Where C++ standard mandates this behavior?

0 Answers
Related