From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2745 invoked by alias); 30 Oct 2010 09:41:51 -0000 Received: (qmail 2735 invoked by uid 22791); 30 Oct 2010 09:41:50 -0000 X-SWARE-Spam-Status: No, hits=-2.4 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00,MISSING_MID X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sat, 30 Oct 2010 09:41:46 +0000 From: "schaub-johannes at web dot de" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/43453] Initialization of char array with string literal fails in mem-initializer X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: schaub-johannes at web dot de X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: In-Reply-To: References: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Date: Sat, 30 Oct 2010 09:41:00 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2010-10/txt/msg02559.txt.bz2 Message-ID: <20101030094100.EQkXz_iMCFcCmiCh0J42jWXYf6_poycLRinlZ5cRYDQ@z> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43453 --- Comment #3 from Johannes Schaub 2010-10-30 09:41:36 UTC --- (In reply to comment #2) > (In reply to comment #1) > > (In reply to comment #0) > > > Fails to compile, but should work: > > > > > > struct A { > > > char x[4]; > > > A():x("bug") { } > > > }; > > > > > > Error i get is: > > > > > > "main.cpp:3: error: array used as initializer" > > > > > > > Why do you think it should work? > > For example, the following equivalent code is invalid as well: > > > > char x [4] ("bug"); > > > > This code is equivalent and is valid. At least, I don't see the Standard > forbidding it. GCC is the only compiler I tested (comeau/edg, clang) that > rejects it. I'm not actually sure anymore about the validity of this code. One can make a point about the initializer not being a mere string literal. At least the draft n3126 makes a difference of this, in that an initializer like "({a, b, c})" is not regarded as a braced-init-list, but rather as a parenthesized expression-list where the initializer list is handed as one argument. So I'm unsure whether an initializer like `("foo")` should be regarded as a string literal or not. I think I will send an issue report about this.