The C++17 standard says:
A template-argument for a non-type template-parameter shall be a converted constant expression...
while
the value of the constant expression shall not shall not be the address of
- a string literal
- a subobject
- some other exeptions...
Per my understanding the rationale behind the exception of string literals is that depending on the implementation it can be that occurrences of A<"abc">
in different translation units may result to different instantiations (as string literals have internal linkage), or it can be that the addresses of string literals are defined at linking time (as string literals are stored in some special read only memory).
The first question is if my understanding is right regarding the rationale behind the exception of string literals?
And the second question is: what is the rationale behind the exception of subobjects of objects that have static storage duration? I suspected that the problem might be in alignment, but the alignment is done in compile time right?