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?

5
  • 1
    That's an array of ordinary character type, char const[]. What am I missing? Commented Aug 21, 2023 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 [...]" Commented Aug 21, 2023 at 11:37
  • 1
    Addendum: a string literal is already const-qualified. Does not say anything about volatile-qualification oc. See eel.is/c++draft/lex.string#1 Commented Aug 21, 2023 at 11:55
  • 1
    @Eljay What am I missing? The definition of ordinary character type Commented Aug 21, 2023 at 12:07
  • 2
    Related to CWG251, CWG2185, CWG2448 Commented Aug 21, 2023 at 13:30

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.