Please refer to this snippet:
#include <type_traits>
#include <string_view>
constexpr std::size_t strlen(char const* s) {
std::size_t n = 0;
while (*s++ != '\0')
++n;
return n;
}
template <std::size_t>
struct X {};
int main() {
constexpr auto pf = __PRETTY_FUNCTION__; // gcc ok; clang ok; (1)
static_assert(std::string_view(__PRETTY_FUNCTION__) == std::string_view("int main()")); // gcc ok; clang ok; (2)
X<strlen(__PRETTY_FUNCTION__)> x; // gcc not ok; clang ok; (3)
}
Clang 8 compiles it, but GCC 8.3 dos not. See on godbolt. GCC fails on line (3)
although lines (1)
and (2)
are ok.
If I am able to declare pf
in line (1)
and use __PRETTY_FUNCTION__
in static_assert
it means that the expression __PRETTY_FUNCTION__
is core constant expression. And if I'm not able do declare X<strlen(__PRETTY_FUNCTION__)> x
it means that strlen(__PRETTY_FUNCTION__)
is not an integral constant expression.
So why strlen(__PRETTY_FUNCTION__)
is not an integral constant expression? Is it implied by the standard, or is it a GCC bug?