8

The current wording in [dcl.init.string] p1 states:

An array of ordinary character type, [...] may be initialized by an ordinary string literal, [...], or by an appropriately-typed string-literal enclosed in braces.

Ordinary character type includes char, signed char, and unsigned char (see [basic.fundamental]). It does not include the cv-qualified versions of those types.

From this, it isn't clear whether an array of const char or volatile char may also be initialized using a string literal, not just an array of char. The wording is unclear because it doesn't say:

An array of cv ordinary character type, [...]

This matters in the following situation:

const char str[] = "test"; // is this valid?

I'm 99% sure that the intention is that you should be able to do it. However, is there a paragraph that definitively allows you to, or is this a wording defect?

Jan Schultke
  • 17,446
  • 6
  • 47
  • 96
  • 1
    That's an array of ordinary character type, `char const[]`. What am I missing? – Eljay Aug 21 '23 at 11:33
  • 6
    @Eljay I guess the question asks if cv-qualified ordinary character type is still ordinary character type. I'd expect wording like "An array of (possibly cv-qualified) ordinary character type [...]" – Yksisarvinen Aug 21 '23 at 11:37
  • 1
    Addendum: a string literal is already const-qualified. Does not say anything about volatile-qualification oc. See https://eel.is/c++draft/lex.string#1 – YSC Aug 21 '23 at 11:55
  • 1
    @Eljay _What am I missing?_ The definition of ordinary character type – Language Lawyer Aug 21 '23 at 12:07
  • 2
    Related to CWG251, CWG2185, CWG2448 – Language Lawyer Aug 21 '23 at 13:30

0 Answers0