classes seem to have a problem caling their constexpr member functions in another constexpr context. For example in this piece of code that I proposed in an earlier question this behaviour can be seen:
struct Foo {
constexpr static bool TRUE() {
return true;
}
static_assert(Foo::TRUE(), ""); //ERROR
};
As the static_assert
depends on Foo::TRUE()
compilation fails because Foo::TRUE()
isn't fully resolved in this context yet.
So how does adding a single template to Foo
solve the whole issue?:
template<int x>
struct Foo {
constexpr static bool TRUE() {
return true;
}
static_assert(Foo::TRUE(), ""); //compiles fine
};
After all these insights this code here shouldn't compile - yet it does. It doesn't seem to make sense, as there isn't any difference to the non-template version.
Also there should always be equally many TRUE()
-functions and static_assert
-calls as there are Foo<>
classes, so the same dependency problem should occur when compiling.
I am using Visual Studio 17 Community Version 15.9.0 - thanks for any help!