So I've got this code (compiling with clang x86-64 14.0.0):
#include <cstdlib>
template <int size>
struct container {
char data[size];
};
template <size_t n>
consteval size_t func2(const char (&string)[n]) {
return 1;
}
template <size_t n>
consteval auto func1(const char (&string)[n]) {
container<func2(string)> result { };
return result;
}
int main() {
static constexpr auto var = func1("hi");
}
The issue comes into play at the func2(string)
function call. Replacing string
with any string literal yields a successful compilation, whereas leaving string
as-is causes a compiler error:
non-type template argument is not a constant expression
I fail to see why this non-type template parameter is not a constant expression, does someone have an explanation?