public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "schaub.johannes at googlemail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/43453] Initialization of char array with string literal fails in mem-initializer
Date: Sat, 14 May 2011 17:28:00 -0000	[thread overview]
Message-ID: <bug-43453-4-ies8MuE6WK@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-43453-4@http.gcc.gnu.org/bugzilla/>

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43453

--- Comment #4 from Johannes Schaub <schaub.johannes at googlemail dot com> 2011-05-14 16:18:58 UTC ---
(In reply to comment #3)
> (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.

Subsequent discussion with Jason showed that this is covered by 8.5p13:

   The form of initialization (using parentheses or =) is generally 
   insignificant, but does matter when the initializer or the entity 
   being initialized has a class type;

As this is an array, the text in the Standard in general has to be interpreted
that a "=" or a "(..)" initializer are equivalent, unless otherwise stated. 

So this is indeed a GCC bug (both that it rejects the member initialization and
the parenthesized non-member initialization).


  parent reply	other threads:[~2011-05-14 16:30 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <bug-43453-4@http.gcc.gnu.org/bugzilla/>
2010-10-30  9:41 ` schaub-johannes at web dot de
2011-05-14 17:28 ` schaub.johannes at googlemail dot com [this message]
2012-01-28  5:55 ` pinskia at gcc dot gnu.org
2014-05-26 10:37 ` paolo.carlini at oracle dot com
2014-06-04 22:31 ` paolo at gcc dot gnu.org
2014-06-04 22:32 ` paolo.carlini at oracle dot com
2014-06-05 20:56 ` jason at gcc dot gnu.org
2010-03-20  3:06 [Bug c++/43453] New: " schaub-johannes at web dot de
2010-08-27 18:06 ` [Bug c++/43453] " giecrilj at stegny dot 2a dot pl
2010-08-28 14:40 ` schaub-johannes at web dot de

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-43453-4-ies8MuE6WK@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).