constexpr member functions that don't use this?
问题 Please consider the following two C++14 programs: Program 1: struct S { constexpr int f() const { return 42; } }; S s; int main() { constexpr int x = s.f(); return x; } Program 2: struct S { constexpr int f() const { return 42; } }; int g(S s) { constexpr int x = s.f(); return x; } int main() { S s; return g(s); } Are neither, either or both of these programs ill-formed? Why/why not? 回答1: Both programs are well-formed. The C++14 standard requires that s.f() be a constant expression because it