5
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]?

NathanOliver
  • 171,901
  • 28
  • 288
  • 402
Sir Visto
  • 683
  • 1
  • 4
  • 9

1 Answers1

7

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.

NathanOliver
  • 171,901
  • 28
  • 288
  • 402