C++ Logo

liaison

Advanced search

[isocpp-wg14/wg21-liaison] Array initialization with parentheses-enclosing string literals

From: Jens Maurer <jens.maurer_at_[hidden]>
Date: Sat, 28 Dec 2024 00:26:41 +0100
const char s1[] = "abc"; // #1
const char s2[] = ("abc"); // #2

#1 is the canonical way to initialize a character array with
a string literal, and is supported by both C and C++.

Recently, a question came up whether #2 is valid, too.
C++ uses grammar non-terminals in this area of the specification,
and it seems pretty clear that parenthesized string literals don't
satisfy the rules, and thus #2 is ill-formed.

C23 superficially has the same rules as C++ in this area,
but I'd appreciate some confirmation.

(Quite a few implementations appear to accept #2. Is that
just a widespread bug?)

Jens

Received on 2024-12-27 23:26:50