* [Bug c++/11633] g++ does not initialize structures when auto-increment variables are used
2003-07-22 20:53 [Bug c++/11633] New: g++ does not initialize structures when auto-increment variables are used msimons at simons-clan dot com
@ 2003-07-22 20:55 ` msimons at simons-clan dot com
2003-07-22 21:41 ` bangerth at dealii dot org
` (11 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: msimons at simons-clan dot com @ 2003-07-22 20:55 UTC (permalink / raw)
To: gcc-bugs
PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11633
------- Additional Comments From msimons at simons-clan dot com 2003-07-22 20:55 -------
Created an attachment (id=4452)
--> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=4452&action=view)
Sample program for structure initialization bug
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c++/11633] g++ does not initialize structures when auto-increment variables are used
2003-07-22 20:53 [Bug c++/11633] New: g++ does not initialize structures when auto-increment variables are used msimons at simons-clan dot com
2003-07-22 20:55 ` [Bug c++/11633] " msimons at simons-clan dot com
@ 2003-07-22 21:41 ` bangerth at dealii dot org
2003-07-22 21:55 ` bangerth at dealii dot org
` (10 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: bangerth at dealii dot org @ 2003-07-22 21:41 UTC (permalink / raw)
To: gcc-bugs
PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11633
------- Additional Comments From bangerth at dealii dot org 2003-07-22 21:41 -------
The question is whether commas in initializers are sequence points. I don't
know whether they are, though.
W.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c++/11633] g++ does not initialize structures when auto-increment variables are used
2003-07-22 20:53 [Bug c++/11633] New: g++ does not initialize structures when auto-increment variables are used msimons at simons-clan dot com
2003-07-22 20:55 ` [Bug c++/11633] " msimons at simons-clan dot com
2003-07-22 21:41 ` bangerth at dealii dot org
@ 2003-07-22 21:55 ` bangerth at dealii dot org
2003-07-22 22:10 ` msimons at simons-clan dot com
` (9 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: bangerth at dealii dot org @ 2003-07-22 21:55 UTC (permalink / raw)
To: gcc-bugs
PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11633
bangerth at dealii dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |nathan at codesourcery dot
| |com
------- Additional Comments From bangerth at dealii dot org 2003-07-22 21:55 -------
Hm, 8.5.1 is the normative part of the standard, but it doesn't say anything
about the order of evaluation. Nathan, language lawyers to the front?
W.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c++/11633] g++ does not initialize structures when auto-increment variables are used
2003-07-22 20:53 [Bug c++/11633] New: g++ does not initialize structures when auto-increment variables are used msimons at simons-clan dot com
` (2 preceding siblings ...)
2003-07-22 21:55 ` bangerth at dealii dot org
@ 2003-07-22 22:10 ` msimons at simons-clan dot com
2003-07-22 23:19 ` msimons at simons-clan dot com
` (8 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: msimons at simons-clan dot com @ 2003-07-22 22:10 UTC (permalink / raw)
To: gcc-bugs
PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11633
------- Additional Comments From msimons at simons-clan dot com 2003-07-22 22:10 -------
static int zap[] = { ++count-1, ++count-1, ++count-1 };
static int baz[] = { ++count-1, ++count-1, ++count-1 };
===
Changing the code to the above... works around this problem in this sample.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c++/11633] g++ does not initialize structures when auto-increment variables are used
2003-07-22 20:53 [Bug c++/11633] New: g++ does not initialize structures when auto-increment variables are used msimons at simons-clan dot com
` (3 preceding siblings ...)
2003-07-22 22:10 ` msimons at simons-clan dot com
@ 2003-07-22 23:19 ` msimons at simons-clan dot com
2003-07-22 23:36 ` bangerth at dealii dot org
` (7 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: msimons at simons-clan dot com @ 2003-07-22 23:19 UTC (permalink / raw)
To: gcc-bugs
PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11633
------- Additional Comments From msimons at simons-clan dot com 2003-07-22 23:19 -------
A friend pointed out language in the gcc.info file which appears to cover
the 'comma' ordering case:
===
* Making side effects happen in the same order as in some other
compiler.
It is never safe to depend on the order of evaluation of side
effects. For example, a function call like this may very well
behave differently from one compiler to another:
void func (int, int);
int i = 2;
func (i++, i++);
There is no guarantee (in either the C or the C++ standard language
definitions) that the increments will be evaluated in any
particular order. Either increment might happen first. `func'
might get the arguments `2, 3', or it might get `3, 2', or even
`2, 2'.
===
I'm not sure if this applies here... and if it *does* apply it seems
inconsistant that things like: ++foo-1, ++foo-1 ... foo++ + 0, foo++ + 0 ...
and value(), value()... all get evaluated left to right, but foo++, foo++ value
gets looked up once, and gets somehow the increment happens N times.
I am very interested in what the c++ language lawyers have to say about this
sample. If it is truely undefined I am *amazed* that practically all of the
remaining commercial unix, c++ compilers do it the same way.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c++/11633] g++ does not initialize structures when auto-increment variables are used
2003-07-22 20:53 [Bug c++/11633] New: g++ does not initialize structures when auto-increment variables are used msimons at simons-clan dot com
` (4 preceding siblings ...)
2003-07-22 23:19 ` msimons at simons-clan dot com
@ 2003-07-22 23:36 ` bangerth at dealii dot org
2003-07-23 1:09 ` msimons at simons-clan dot com
` (6 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: bangerth at dealii dot org @ 2003-07-22 23:36 UTC (permalink / raw)
To: gcc-bugs
PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11633
------- Additional Comments From bangerth at dealii dot org 2003-07-22 23:36 -------
Commas separating function call arguments are not sequence points, so
foo(x++, x++)
can really be evaluated in different ways. On the other hand, commas in
comma expressions as in
while (x++, x++)
_are_ sequence points, so the order of evaluation is defined. The only question
which I can't answer from the standard is whether commas in initializer expressions
are sequence points.
If the order of evaluation is undefined, then the fact that some compilers implement
one way of doing things is not a reason to rely on a feature. Likewise,
random changes to the code _may_ make the code do what you expect, but
the code still triggers undefined behavior and may break again with
the next compiler version. The only way around this is to make the code
use only well defined semantics.
W.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c++/11633] g++ does not initialize structures when auto-increment variables are used
2003-07-22 20:53 [Bug c++/11633] New: g++ does not initialize structures when auto-increment variables are used msimons at simons-clan dot com
` (5 preceding siblings ...)
2003-07-22 23:36 ` bangerth at dealii dot org
@ 2003-07-23 1:09 ` msimons at simons-clan dot com
2003-07-23 9:04 ` nathan at gcc dot gnu dot org
` (5 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: msimons at simons-clan dot com @ 2003-07-23 1:09 UTC (permalink / raw)
To: gcc-bugs
PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11633
------- Additional Comments From msimons at simons-clan dot com 2003-07-23 01:09 -------
For the C language, in a draft of the C99 spec around section 6.7.8
"Initialization", it talks about initialization lists.
===
[#23] The order in which any side effects occur among the
initialization list expressions is unspecified. (121)
121 - In particular, the evaluation order need not be the same
as the order of subobject initialization.
===
Perhaps someone with the c++ standard handy can find "initialization lists".
If the same holds true for the c++ standard, then I agree this is a code bug
not a compiler bug. :(
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c++/11633] g++ does not initialize structures when auto-increment variables are used
2003-07-22 20:53 [Bug c++/11633] New: g++ does not initialize structures when auto-increment variables are used msimons at simons-clan dot com
` (6 preceding siblings ...)
2003-07-23 1:09 ` msimons at simons-clan dot com
@ 2003-07-23 9:04 ` nathan at gcc dot gnu dot org
2003-08-23 17:11 ` pinskia at gcc dot gnu dot org
` (4 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: nathan at gcc dot gnu dot org @ 2003-07-23 9:04 UTC (permalink / raw)
To: gcc-bugs
PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11633
------- Additional Comments From nathan at gcc dot gnu dot org 2003-07-23 09:04 -------
I beleive the code to be ill formed. Looking at 8.5.1 of the std does not
help. brace enclosed initializer lists can only be used for aggregates. 1.9
talks about sequence points and full-expression. The initializers in an
initializer list are not full-expressions, because they'r part of the initializer.
AFAICT, The comma symbol is only a sequence point when it is the comma-operator
(and does not resolve to an overloaded function!)
I suspect when designtated initializers are used in different C99 compilers,
you'll find the behaviour is not the same across all compilers.
The Defect list does not talk about this case, I will ask the committee.
I would be surprised if the intent is to be anything different from
C90/C99.
nathan
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c++/11633] g++ does not initialize structures when auto-increment variables are used
2003-07-22 20:53 [Bug c++/11633] New: g++ does not initialize structures when auto-increment variables are used msimons at simons-clan dot com
` (7 preceding siblings ...)
2003-07-23 9:04 ` nathan at gcc dot gnu dot org
@ 2003-08-23 17:11 ` pinskia at gcc dot gnu dot org
2003-11-21 16:55 ` pinskia at gcc dot gnu dot org
` (3 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2003-08-23 17:11 UTC (permalink / raw)
To: gcc-bugs
PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11633
pinskia at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|3.4 |---
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c++/11633] g++ does not initialize structures when auto-increment variables are used
2003-07-22 20:53 [Bug c++/11633] New: g++ does not initialize structures when auto-increment variables are used msimons at simons-clan dot com
` (8 preceding siblings ...)
2003-08-23 17:11 ` pinskia at gcc dot gnu dot org
@ 2003-11-21 16:55 ` pinskia at gcc dot gnu dot org
2003-11-21 16:57 ` pinskia at gcc dot gnu dot org
` (2 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2003-11-21 16:55 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2003-11-21 16:55 -------
Lets confirm this and then ...
--
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Ever Confirmed| |1
Last reconfirmed|0000-00-00 00:00:00 |2003-11-21 16:55:28
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11633
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c++/11633] g++ does not initialize structures when auto-increment variables are used
2003-07-22 20:53 [Bug c++/11633] New: g++ does not initialize structures when auto-increment variables are used msimons at simons-clan dot com
` (9 preceding siblings ...)
2003-11-21 16:55 ` pinskia at gcc dot gnu dot org
@ 2003-11-21 16:57 ` pinskia at gcc dot gnu dot org
2004-04-30 1:47 ` [Bug c++/11633] [DR 430] " pinskia at gcc dot gnu dot org
2004-04-30 18:17 ` pinskia at gcc dot gnu dot org
12 siblings, 0 replies; 14+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2003-11-21 16:57 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2003-11-21 16:57 -------
To suspend it while the issue is going in c++ standards committee.
--
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |SUSPENDED
Keywords| |wrong-code
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11633
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c++/11633] [DR 430] g++ does not initialize structures when auto-increment variables are used
2003-07-22 20:53 [Bug c++/11633] New: g++ does not initialize structures when auto-increment variables are used msimons at simons-clan dot com
` (10 preceding siblings ...)
2003-11-21 16:57 ` pinskia at gcc dot gnu dot org
@ 2004-04-30 1:47 ` pinskia at gcc dot gnu dot org
2004-04-30 18:17 ` pinskia at gcc dot gnu dot org
12 siblings, 0 replies; 14+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-04-30 1:47 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2004-04-30 01:13 -------
The DR report is 430: <http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/cwg_active.html#430>.
--
What |Removed |Added
----------------------------------------------------------------------------
Summary|g++ does not initialize |[DR 430] g++ does not
|structures when auto- |initialize structures when
|increment variables are used|auto-increment variables are
| |used
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11633
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c++/11633] [DR 430] g++ does not initialize structures when auto-increment variables are used
2003-07-22 20:53 [Bug c++/11633] New: g++ does not initialize structures when auto-increment variables are used msimons at simons-clan dot com
` (11 preceding siblings ...)
2004-04-30 1:47 ` [Bug c++/11633] [DR 430] " pinskia at gcc dot gnu dot org
@ 2004-04-30 18:17 ` pinskia at gcc dot gnu dot org
12 siblings, 0 replies; 14+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-04-30 18:17 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2004-04-30 17:25 -------
Adding what I got in my email:
From: msimons@moria.simons-clan.com
Subject: Re: [Bug c++/11633] [DR 430] g++ does not initialize structures when auto-increment
variables are used
Date: April 30, 2004 13:19:11 EDT
To: jsa@edg.com
Cc: msimons@simons-clan.com, pinskia@gcc.gnu.org
Steve Adamczyk wrote:
http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/cwg_active.html#430
I believe the standard is clear that each initializer expression in the
above is a full-expression (1.9 intro.execution/12-13; see also issue
392) and therefore there is a sequence point after each expression
(1.9 intro.execution/16). I agree that the standard does not seem to
dictate the order in which the expressions are evaluated, and perhaps
it should.
Does anyone know of a compiler that would not evaluate the expressions
left to right?
Steve,
Actually there is one, that does not do left to right: gcc/C++.
None of the post increment operations take effect until after the
statement finishes. So in the sample code gcc stores 23 into all
positions in the array.
The commercial vendor C++ compilers for AIX, Solaris, Tru64, HPUX
(parisc and ia64), and Windows, all do sequence points at each ','
in the initializer list.
So I opened a bug report against gcc (#11633, link to bug below).
Unfortunately if the C++ standard does not say one way or the other
then gcc/C++ is unlikely to change.
On Fri, Apr 30, 2004 at 01:13:38AM -0000, pinskia at gcc dot gnu dot org wrote:
------- Additional Comments From pinskia at gcc dot gnu dot org 2004-04-30 01:13 -------
The DR report is 430: <http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/cwg_active.html#430>.
--
What |Removed |Added
----------------------------------------------------------------------------
Summary|g++ does not initialize |[DR 430] g++ does not
|structures when auto- |initialize structures when
|increment variables are used|auto-increment variables are
| |used
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11633
------- You are receiving this mail because: -------
You reported the bug, or are watching the reporter.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11633
^ permalink raw reply [flat|nested] 14+ messages in thread