public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/43453] Initialization of char array with string literal fails in mem-initializer
[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
` (5 subsequent siblings)
6 siblings, 0 replies; 9+ messages in thread
From: schaub-johannes at web dot de @ 2010-10-30 9:41 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43453
--- Comment #3 from Johannes Schaub <schaub-johannes at web dot de> 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.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/43453] Initialization of char array with string literal fails in mem-initializer
[not found] <bug-43453-4@http.gcc.gnu.org/bugzilla/>
2010-10-30 9:41 ` [Bug c++/43453] Initialization of char array with string literal fails in mem-initializer schaub-johannes at web dot de
@ 2011-05-14 17:28 ` schaub.johannes at googlemail dot com
2012-01-28 5:55 ` pinskia at gcc dot gnu.org
` (4 subsequent siblings)
6 siblings, 0 replies; 9+ messages in thread
From: schaub.johannes at googlemail dot com @ 2011-05-14 17:28 UTC (permalink / raw)
To: gcc-bugs
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).
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/43453] Initialization of char array with string literal fails in mem-initializer
[not found] <bug-43453-4@http.gcc.gnu.org/bugzilla/>
2010-10-30 9:41 ` [Bug c++/43453] Initialization of char array with string literal fails in mem-initializer schaub-johannes at web dot de
2011-05-14 17:28 ` schaub.johannes at googlemail dot com
@ 2012-01-28 5:55 ` pinskia at gcc dot gnu.org
2014-05-26 10:37 ` paolo.carlini at oracle dot com
` (3 subsequent siblings)
6 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2012-01-28 5:55 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43453
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |rejects-valid
Target|i686-pc-linux-gnu |
Status|UNCONFIRMED |NEW
Last reconfirmed| |2012-01-28
Host|i686-pc-linux-gnu |
Ever Confirmed|0 |1
Known to fail| |4.7.0
--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> 2012-01-28 05:43:59 UTC ---
Confirmed.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/43453] Initialization of char array with string literal fails in mem-initializer
[not found] <bug-43453-4@http.gcc.gnu.org/bugzilla/>
` (2 preceding siblings ...)
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
` (2 subsequent siblings)
6 siblings, 0 replies; 9+ messages in thread
From: paolo.carlini at oracle dot com @ 2014-05-26 10:37 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=43453
Paolo Carlini <paolo.carlini at oracle dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |ASSIGNED
CC|gcc-bugs at gcc dot gnu.org |
Assignee|unassigned at gcc dot gnu.org |paolo.carlini at oracle dot com
Target Milestone|--- |4.10.0
--- Comment #6 from Paolo Carlini <paolo.carlini at oracle dot com> ---
Mine.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/43453] Initialization of char array with string literal fails in mem-initializer
[not found] <bug-43453-4@http.gcc.gnu.org/bugzilla/>
` (3 preceding siblings ...)
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
6 siblings, 0 replies; 9+ messages in thread
From: paolo at gcc dot gnu.org @ 2014-06-04 22:31 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=43453
--- Comment #7 from paolo at gcc dot gnu.org <paolo at gcc dot gnu.org> ---
Author: paolo
Date: Wed Jun 4 22:30:39 2014
New Revision: 211248
URL: http://gcc.gnu.org/viewcvs?rev=211248&root=gcc&view=rev
Log:
/cp
2014-06-04 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/43453
* typeck.c (cp_build_modify_expr): Handle array of characters
initialized by a string literal.
* decl.c (check_initializer): Handle parenthesized string literal
as initializer.
* typeck2.c (store_init_value): Remove redundant check.
/testsuite
2014-06-04 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/43453
* g++.dg/init/pr43453.C: New.
Added:
trunk/gcc/testsuite/g++.dg/init/pr43453.C
Modified:
trunk/gcc/cp/ChangeLog
trunk/gcc/cp/decl.c
trunk/gcc/cp/typeck.c
trunk/gcc/cp/typeck2.c
trunk/gcc/testsuite/ChangeLog
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/43453] Initialization of char array with string literal fails in mem-initializer
[not found] <bug-43453-4@http.gcc.gnu.org/bugzilla/>
` (4 preceding siblings ...)
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
6 siblings, 0 replies; 9+ messages in thread
From: paolo.carlini at oracle dot com @ 2014-06-04 22:32 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=43453
Paolo Carlini <paolo.carlini at oracle dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution|--- |FIXED
Assignee|paolo.carlini at oracle dot com |unassigned at gcc dot gnu.org
--- Comment #8 from Paolo Carlini <paolo.carlini at oracle dot com> ---
Fixed for 4.10.0.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/43453] Initialization of char array with string literal fails in mem-initializer
[not found] <bug-43453-4@http.gcc.gnu.org/bugzilla/>
` (5 preceding siblings ...)
2014-06-04 22:32 ` paolo.carlini at oracle dot com
@ 2014-06-05 20:56 ` jason at gcc dot gnu.org
6 siblings, 0 replies; 9+ messages in thread
From: jason at gcc dot gnu.org @ 2014-06-05 20:56 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=43453
--- Comment #9 from Jason Merrill <jason at gcc dot gnu.org> ---
Author: jason
Date: Thu Jun 5 20:55:44 2014
New Revision: 211290
URL: http://gcc.gnu.org/viewcvs?rev=211290&root=gcc&view=rev
Log:
PR c++/43453
* decl.c (check_initializer): Collapse a TREE_LIST here.
* typeck2.c (store_init_value): Not here.
Modified:
trunk/gcc/cp/ChangeLog
trunk/gcc/cp/decl.c
trunk/gcc/cp/typeck2.c
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/43453] Initialization of char array with string literal fails in mem-initializer
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
1 sibling, 0 replies; 9+ messages in thread
From: schaub-johannes at web dot de @ 2010-08-28 14:40 UTC (permalink / raw)
To: gcc-bugs
------- Comment #2 from schaub-johannes at web dot de 2010-08-28 14:39 -------
(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.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43453
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/43453] Initialization of char array with string literal fails in mem-initializer
2010-03-20 3:06 [Bug c++/43453] New: " schaub-johannes at web dot de
@ 2010-08-27 18:06 ` giecrilj at stegny dot 2a dot pl
2010-08-28 14:40 ` schaub-johannes at web dot de
1 sibling, 0 replies; 9+ messages in thread
From: giecrilj at stegny dot 2a dot pl @ 2010-08-27 18:06 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from giecrilj at stegny dot 2a dot pl 2010-08-27 18:06 -------
(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");
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43453
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2014-06-05 20:56 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <bug-43453-4@http.gcc.gnu.org/bugzilla/>
2010-10-30 9:41 ` [Bug c++/43453] Initialization of char array with string literal fails in mem-initializer schaub-johannes at web dot de
2011-05-14 17:28 ` schaub.johannes at googlemail dot com
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
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).