Let's say we have
template <const char*>
struct A{};
// static storage
const char a[] = "asd";
const char* p = "asd";
This instantiation
A<a>{};
is okay for compiler. And this is understandable - array a
decays to pointer to first element. But if we instantiate A
with p
like this
A<p>{};
compiler gives an error:
error: non-type template argument of type 'char *' is not a constant expression
Why doesn't Standard allow to specify named variable of type const char*
or just string literal "asd"
, which is btw lvalue itself, as a template argument?
x;`