On Sat, 14 Jun 2025 at 13:32, саша савельев wrote: > > > To whom it may concern > > Why we can’t use <const char*> in this context? > > #include < iostream > > template < auto N > > void f () { > std::cout << N << std::endl ; > } > int main () { > f < 1 >(); > f < '!' >(); > f < "!!" >(); // error > return 0 ; > }
Hello, this is a general C++ question, so is off topic on this mailing list which is for discussing the development of GCC. Somewhere like stackoverflow.com would be more appropriate for learning how C++ works. The reason you can't do this is because the C++ standard says you can't: https://wg21.link/temp.arg.nontype#6 I think the reason is that the address of a string literal is not portable, even between different source files: https://wg21.link/lex.string#note-4 It's unspecified whether calling f<"!!">() in two different places would even be the same specialization of the template, or a different specialization each time. To avoid surprises and non-portable behaviour, you're just not allowed to do that. > > > Alexander and his classmates