Why is this passed as function parameter of a constexpr function not a constant expression? [duplicate]
In this trivial example, test2 fails to compile even though test1 succeeds, and I don't see why that is the case. If arr[i] is suitable for a return value from a function marked constexpr then why can it not be used as a non-type template argument? template<char c> struct t { static const char value = c; }; template <unsigned N> constexpr char test1(const char (&arr)[N], unsigned i) { return arr[i]; } template <unsigned N> constexpr char test2(const char (&arr)[N], unsigned i) { return t<arr[i]>::value; } int main() { char a = test1("Test", 0); //Compiles OK char b = test2("Test", 0); //error:
0 upvotes
View original discussion ↗
Comments
Sign in or sign up to comment and upvote.
No comments yet.