Template type deduction for char array

Viewed 147
template<typename T>
class X;

int main() {
    X<decltype("")> x;
}

Why does g++ deduce T as const char (&)[1] and not simply const char[1]?

1 Answers

Unlike every other literal that is an rvalue, string literals are lvalues. decltype applied to an lvalue expression gives you a reference so const char (&)[1] is the correct behavior.

Related