public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/19544] New: Difference in behaviour if default constructor added
@ 2005-01-20 12:51 chris at bubblescope dot net
2005-01-20 14:56 ` [Bug libstdc++/19544] " pinskia at gcc dot gnu dot org
` (9 more replies)
0 siblings, 10 replies; 11+ messages in thread
From: chris at bubblescope dot net @ 2005-01-20 12:51 UTC (permalink / raw)
To: gcc-bugs
While looking at PR 19510, I noticed the following strangeness.
Consider:
--
#include<vector>
struct ptr
{
int* a;
ptr() {}
};
std::vector<ptr> v(1);
--
At -O3 -Wall
This code produces the error message:
...../include/c++/4.0.0/bits/stl_construct.h: In function 'void
__static_initialization_and_destruction_0(int,int)':
...../include/c++/4.0.0/bits/stl_construct.h:81: warning: 'SR.186' is used
uninitalized in this function
This warning is not generated if I declare ptr without a default constructor,
although 12.1/7 seems to imply that the default generated constructor should be
exactly what I have written down.
--
Summary: Difference in behaviour if default constructor added
Product: gcc
Version: 4.0.0
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: chris at bubblescope dot net
CC: caj at cs dot york dot ac dot uk,gcc-bugs at gcc dot gnu
dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19544
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug libstdc++/19544] Difference in behaviour if default constructor added
2005-01-20 12:51 [Bug c++/19544] New: Difference in behaviour if default constructor added chris at bubblescope dot net
@ 2005-01-20 14:56 ` pinskia at gcc dot gnu dot org
2005-01-20 15:14 ` chris at bubblescope dot net
` (8 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-01-20 14:56 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2005-01-20 14:56 -------
This is a library bug.
--
What |Removed |Added
----------------------------------------------------------------------------
Component|c++ |libstdc++
Keywords| |diagnostic
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19544
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug libstdc++/19544] Difference in behaviour if default constructor added
2005-01-20 12:51 [Bug c++/19544] New: Difference in behaviour if default constructor added chris at bubblescope dot net
2005-01-20 14:56 ` [Bug libstdc++/19544] " pinskia at gcc dot gnu dot org
@ 2005-01-20 15:14 ` chris at bubblescope dot net
2005-01-20 15:21 ` pinskia at gcc dot gnu dot org
` (7 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: chris at bubblescope dot net @ 2005-01-20 15:14 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From chris at bubblescope dot net 2005-01-20 15:14 -------
Heres another test-case...
#include<algorithm>
struct ptr
{
int* a;
ptr() {}
};
struct foo
{
ptr array[1];
foo() { std::uninitalized_fill_n(array,1,ptr()); }
};
foo f;
Which shows it isn't limited to libstdc++ (assuming uninitalized_fill_n is
correct, which I'm fairly sure it is).
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19544
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug libstdc++/19544] Difference in behaviour if default constructor added
2005-01-20 12:51 [Bug c++/19544] New: Difference in behaviour if default constructor added chris at bubblescope dot net
2005-01-20 14:56 ` [Bug libstdc++/19544] " pinskia at gcc dot gnu dot org
2005-01-20 15:14 ` chris at bubblescope dot net
@ 2005-01-20 15:21 ` pinskia at gcc dot gnu dot org
2005-01-20 19:19 ` gdr at integrable-solutions dot net
` (6 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-01-20 15:21 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2005-01-20 15:21 -------
Invalid, as you default constructor is not doing its job of initializing:
ptr() {}
--
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19544
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug libstdc++/19544] Difference in behaviour if default constructor added
2005-01-20 12:51 [Bug c++/19544] New: Difference in behaviour if default constructor added chris at bubblescope dot net
` (2 preceding siblings ...)
2005-01-20 15:21 ` pinskia at gcc dot gnu dot org
@ 2005-01-20 19:19 ` gdr at integrable-solutions dot net
2005-01-20 19:25 ` chris at bubblescope dot net
` (5 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: gdr at integrable-solutions dot net @ 2005-01-20 19:19 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From gdr at integrable-solutions dot net 2005-01-20 19:19 -------
Subject: Re: New: Difference in behaviour if default constructor added
"chris at bubblescope dot net" <gcc-bugzilla@gcc.gnu.org> writes:
| While looking at PR 19510, I noticed the following strangeness.
|
| Consider:
| --
| #include<vector>
| struct ptr
| {
| int* a;
| ptr() {}
| };
| std::vector<ptr> v(1);
| --
| At -O3 -Wall
| This code produces the error message:
| ...../include/c++/4.0.0/bits/stl_construct.h: In function 'void
| __static_initialization_and_destruction_0(int,int)':
| ...../include/c++/4.0.0/bits/stl_construct.h:81: warning: 'SR.186' is used
| uninitalized in this function
|
| This warning is not generated if I declare ptr without a default constructor,
| although 12.1/7 seems to imply that the default generated constructor should be
| exactly what I have written down.
This is a bug in your code. Can you explain me why it is suddenly a
bug in the library?
-- Gaby
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19544
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug libstdc++/19544] Difference in behaviour if default constructor added
2005-01-20 12:51 [Bug c++/19544] New: Difference in behaviour if default constructor added chris at bubblescope dot net
` (3 preceding siblings ...)
2005-01-20 19:19 ` gdr at integrable-solutions dot net
@ 2005-01-20 19:25 ` chris at bubblescope dot net
2005-01-20 19:42 ` gdr at integrable-solutions dot net
` (4 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: chris at bubblescope dot net @ 2005-01-20 19:25 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From chris at bubblescope dot net 2005-01-20 19:25 -------
I never thought it was a bug in the library :)
I however throught (incorrectly) that copying an unassigned pointer was valid,
mainly as some other test case was considering constructing
std::vector<std::list<int>::iterator> v(1). Now I realise that in fact copying
an unassigned pointer is undefined behaviour, so of course the error is fine :)
Sorry
I'm still curious as to why the error doesn't appear if let g++ generate a
default constructor, as from my reading of 12.1/7, the default generated
constructor should be "ptr() {}", so the error should still appear. Am I reading
it wrong?
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19544
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug libstdc++/19544] Difference in behaviour if default constructor added
2005-01-20 12:51 [Bug c++/19544] New: Difference in behaviour if default constructor added chris at bubblescope dot net
` (4 preceding siblings ...)
2005-01-20 19:25 ` chris at bubblescope dot net
@ 2005-01-20 19:42 ` gdr at integrable-solutions dot net
2005-01-20 20:46 ` bangerth at dealii dot org
` (3 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: gdr at integrable-solutions dot net @ 2005-01-20 19:42 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From gdr at integrable-solutions dot net 2005-01-20 19:42 -------
Subject: Re: Difference in behaviour if default constructor added
"chris at bubblescope dot net" <gcc-bugzilla@gcc.gnu.org> writes:
| I'm still curious as to why the error doesn't appear if let g++ generate a
| default constructor, as from my reading of 12.1/7, the default generated
| constructor should be "ptr() {}", so the error should still appear. Am I reading
| it wrong?
The syntax "ptr()" invokes value initialization, which has the effect of
initializing ptr to zero. See the relevant section in the standard.
-- Gaby
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19544
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug libstdc++/19544] Difference in behaviour if default constructor added
2005-01-20 12:51 [Bug c++/19544] New: Difference in behaviour if default constructor added chris at bubblescope dot net
` (5 preceding siblings ...)
2005-01-20 19:42 ` gdr at integrable-solutions dot net
@ 2005-01-20 20:46 ` bangerth at dealii dot org
2005-01-20 21:04 ` caj at cs dot york dot ac dot uk
` (2 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: bangerth at dealii dot org @ 2005-01-20 20:46 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From bangerth at dealii dot org 2005-01-20 20:46 -------
To be completely clear, the compiler generated default constructor is
ptr() : a(0) {}
not
ptr() {}
Thus, it _does_ initialize 'a'.
W.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19544
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug libstdc++/19544] Difference in behaviour if default constructor added
2005-01-20 12:51 [Bug c++/19544] New: Difference in behaviour if default constructor added chris at bubblescope dot net
` (6 preceding siblings ...)
2005-01-20 20:46 ` bangerth at dealii dot org
@ 2005-01-20 21:04 ` caj at cs dot york dot ac dot uk
2005-01-21 2:25 ` gdr at integrable-solutions dot net
2005-01-21 2:28 ` gdr at integrable-solutions dot net
9 siblings, 0 replies; 11+ messages in thread
From: caj at cs dot york dot ac dot uk @ 2005-01-20 21:04 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From caj at cs dot york dot ac dot uk 2005-01-20 21:04 -------
Subject: Re: Difference in behaviour if default constructor
added
bangerth at dealii dot org wrote:
>------- Additional Comments From bangerth at dealii dot org 2005-01-20 20:46 -------
>To be completely clear, the compiler generated default constructor is
> ptr() : a(0) {}
>not
> ptr() {}
>Thus, it _does_ initialize 'a'.
>
>W.
>
>
>
Sorry to be dense, but I want to follow this.. Is this a choice g++
makes, or is it mandated by the standard? Is this defined by something
other than 12.1/7, or does 12.1/7 actually require this and I'm
misreading it?
Thank you
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19544
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug libstdc++/19544] Difference in behaviour if default constructor added
2005-01-20 12:51 [Bug c++/19544] New: Difference in behaviour if default constructor added chris at bubblescope dot net
` (7 preceding siblings ...)
2005-01-20 21:04 ` caj at cs dot york dot ac dot uk
@ 2005-01-21 2:25 ` gdr at integrable-solutions dot net
2005-01-21 2:28 ` gdr at integrable-solutions dot net
9 siblings, 0 replies; 11+ messages in thread
From: gdr at integrable-solutions dot net @ 2005-01-21 2:25 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From gdr at integrable-solutions dot net 2005-01-21 02:25 -------
Subject: Re: Difference in behaviour if default constructor added
"bangerth at dealii dot org" <gcc-bugzilla@gcc.gnu.org> writes:
| To be completely clear, the compiler generated default constructor is
| ptr() : a(0) {}
| not
| ptr() {}
| Thus, it _does_ initialize 'a'.
I don't follow you here.
If one writes
ptrwrapper() : ptr() { }
with the above syntax, ptr is *value initialized*, e.g. it is set to
zero. That is not to be confused with callig the default constructor
(which is trivial) for ptr.
-- Gaby
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19544
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug libstdc++/19544] Difference in behaviour if default constructor added
2005-01-20 12:51 [Bug c++/19544] New: Difference in behaviour if default constructor added chris at bubblescope dot net
` (8 preceding siblings ...)
2005-01-21 2:25 ` gdr at integrable-solutions dot net
@ 2005-01-21 2:28 ` gdr at integrable-solutions dot net
9 siblings, 0 replies; 11+ messages in thread
From: gdr at integrable-solutions dot net @ 2005-01-21 2:28 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From gdr at integrable-solutions dot net 2005-01-21 02:28 -------
Subject: Re: Difference in behaviour if default constructor added
"caj at cs dot york dot ac dot uk" <gcc-bugzilla@gcc.gnu.org> writes:
| Subject: Re: Difference in behaviour if default constructor
| added
|
| bangerth at dealii dot org wrote:
|
| >------- Additional Comments From bangerth at dealii dot org 2005-01-20 20:46 -------
| >To be completely clear, the compiler generated default constructor is
| > ptr() : a(0) {}
| >not
| > ptr() {}
| >Thus, it _does_ initialize 'a'.
| >
| >W.
| >
| >
| >
| Sorry to be dense, but I want to follow this.. Is this a choice g++
| makes, or is it mandated by the standard? Is this defined by something
| other than 12.1/7, or does 12.1/7 actually require this and I'm
| misreading it?
You mean when you write "ptr()" in the member initializer list? Check
for value initialization in 8.5.
-- Gaby
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19544
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2005-01-21 2:28 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-01-20 12:51 [Bug c++/19544] New: Difference in behaviour if default constructor added chris at bubblescope dot net
2005-01-20 14:56 ` [Bug libstdc++/19544] " pinskia at gcc dot gnu dot org
2005-01-20 15:14 ` chris at bubblescope dot net
2005-01-20 15:21 ` pinskia at gcc dot gnu dot org
2005-01-20 19:19 ` gdr at integrable-solutions dot net
2005-01-20 19:25 ` chris at bubblescope dot net
2005-01-20 19:42 ` gdr at integrable-solutions dot net
2005-01-20 20:46 ` bangerth at dealii dot org
2005-01-20 21:04 ` caj at cs dot york dot ac dot uk
2005-01-21 2:25 ` gdr at integrable-solutions dot net
2005-01-21 2:28 ` gdr at integrable-solutions dot net
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).