Consider this non-templated class
struct Foo {
constexpr static bool TRUE() {
return true;
}
};
Calling Foo::TRUE()
from outside works fine:
int main() {
static_assert(Foo::TRUE(), "");
}
but not when called from Foo
itself:
struct Foo {
constexpr static bool TRUE() {
return true;
}
static_assert(Foo::TRUE(), ""); //ERROR
};
Error (active) E0028 expression must have a constant value
Error C2131 expression did not evaluate to a constant
Even weirder is that this can be "fixed" by providing the class a template:
template<int x>
struct Foo {
constexpr static bool TRUE() {
return true;
}
static_assert(Foo::TRUE(), ""); //compiles fine
};
int main() {
}
Even though Foo::TRUE()
has nothing to do with int x
.
What's going on?
I am using Visual Studio 17 Community Version 15.9.0 - thanks for any help