Full name of submitter (unless configured in github; will be published with the issue): Jiang An
Reference (section label): [dcl.init.general], [dcl.init.string]
[dcl.init.general] p16.3:
If the destination type is an array of characters, an array of char8_t, an array of char16_t, an array of char32_t, or an array of wchar_t, and the initializer is a string-literal, see [dcl.init.string].
[dcl.init.string] p1
An array of ordinary character type ([basic.fundamental]), char8_t array, char16_t array, char32_t array, or wchar_t array may be initialized by an ordinary string literal, UTF-8 string literal, UTF-16 string literal, UTF-32 string literal, or wide string literal, respectively, or by an appropriately-typed string-literal enclosed in braces ([lex.string]). [...]
The syntactic forms of such initializers are not very clear and there's implementation divergence.
"Good" forms:
char a[] = "foo"; - accepted by all known implementations, and clarified to be valid in notes;
char a[]("foo"); - accepted by all known implementations;
char a[]{"foo"}; - accepted by all known (C++11 and later) implementations;
char a[] = {"foo"}; - accepted by all known (C++11 and later) implementations.
Controversial forms with additonal parentheses:
Weird forms with additional braces:
char arr[]{{"foo"}}; - accepted by MSVC and rejected by others;
char arr[] = {{"foo"}}; - same as above.
It seems that we should clarify the permitted syntactic forms, which should include "good" and controversial forms and exclude weird forms.
Link to reflector thread (if any):
Issue description:
Suggested resolution:
Full name of submitter (unless configured in github; will be published with the issue): Jiang An
Reference (section label): [dcl.init.general], [dcl.init.string]
[dcl.init.general] p16.3:
[dcl.init.string] p1
The syntactic forms of such initializers are not very clear and there's implementation divergence.
"Good" forms:
char a[] = "foo";- accepted by all known implementations, and clarified to be valid in notes;char a[]("foo");- accepted by all known implementations;char a[]{"foo"};- accepted by all known (C++11 and later) implementations;char a[] = {"foo"};- accepted by all known (C++11 and later) implementations.Controversial forms with additonal parentheses:
char a[] = ("foo");- diagnosed by GCC (and EDG & Comeau per clang ("foo") accepted as char[] initializer llvm/llvm-project#8418); silently accepted by other implementations;char a[](("foo"));- likely same as above;char a[]{("foo")};- likely same as above;char a[] = {("foo")};- likely same as above.Weird forms with additional braces:
char arr[]{{"foo"}};- accepted by MSVC and rejected by others;char arr[] = {{"foo"}};- same as above.It seems that we should clarify the permitted syntactic forms, which should include "good" and controversial forms and exclude weird forms.
Link to reflector thread (if any):
Issue description:
Suggested resolution: