public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/48859] New: Regression: incorrect "uninitialized const member" error on new without new-initializer
@ 2011-05-03 23:56 jyasskin at gcc dot gnu.org
2011-05-04 0:03 ` [Bug c++/48859] " pinskia at gcc dot gnu.org
` (9 more replies)
0 siblings, 10 replies; 11+ messages in thread
From: jyasskin at gcc dot gnu.org @ 2011-05-03 23:56 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48859
Summary: Regression: incorrect "uninitialized const member"
error on new without new-initializer
Product: gcc
Version: 4.6.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: jyasskin@gcc.gnu.org
$ cat test.cc
struct HasConstructor {
HasConstructor() {}
};
class ConstMember {
const HasConstructor empty_;
};
void foo() {
new ConstMember;
}
$ g++-mp-4.5 -c test.cc
$ g++-mp-4.6 -c test.cc
test.cc: In function 'void foo()':
test.cc:10:7: error: uninitialized const member in 'class ConstMember' using
'new' without new-initializer
test.cc:6:24: note: 'ConstMember::empty_' should be initialized
$
[expr.new]p15 says, "If the new-initializer is omitted: If T is a (possibly
cv-qualified) non-POD class type (or array thereof), the object is
default-initialized (8.5) If T is a const-qualified type, the underlying class
type shall have a user-declared default constructor."
T is ConstMember and is not const-qualified, so the object is
default-initialized.
[dcl.init]p5 says, "To default-initialize an object of type T means: if T is a
non-POD class type (clause 9), the default constructor for T is called (and the
initialization is ill-formed if T has no accessible default constructor);"
[class.ctor]p7 says, "The implicitly-defined default constructor performs the
set of initializations of the class that would be performed by a user-written
default constructor for that class with an empty mem- initializer-list (12.6.2)
and an empty function body. If that user-written default constructor would be
ill- formed, the program is ill-formed."
The empty user-written default constructor for ConstMember is well-formed, and
I don't see any other wording saying that const members prevent the creation of
a default constructor. Further, a local variable with no initializer
successfully compiles. So I believe gcc-4.6 is wrong here and gcc-4.5 was
right.
I don't see anything in the C++0x draft that would change the right behavior
here.
The workaround, of course, is to define the empty default constructor in
ConstMember. (In C++0x mode, "=default" does not work around the problem.)
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/48859] Regression: incorrect "uninitialized const member" error on new without new-initializer
2011-05-03 23:56 [Bug c++/48859] New: Regression: incorrect "uninitialized const member" error on new without new-initializer jyasskin at gcc dot gnu.org
@ 2011-05-04 0:03 ` pinskia at gcc dot gnu.org
2011-05-04 12:35 ` [Bug c++/48859] [4.6/4.7 Regression] " redi at gcc dot gnu.org
` (8 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu.org @ 2011-05-04 0:03 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48859
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> 2011-05-04 00:03:08 UTC ---
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29043
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25811
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/48859] [4.6/4.7 Regression] incorrect "uninitialized const member" error on new without new-initializer
2011-05-03 23:56 [Bug c++/48859] New: Regression: incorrect "uninitialized const member" error on new without new-initializer jyasskin at gcc dot gnu.org
2011-05-04 0:03 ` [Bug c++/48859] " pinskia at gcc dot gnu.org
@ 2011-05-04 12:35 ` redi at gcc dot gnu.org
2011-05-04 12:36 ` redi at gcc dot gnu.org
` (7 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: redi at gcc dot gnu.org @ 2011-05-04 12:35 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48859
--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> 2011-05-04 12:33:38 UTC ---
(In reply to comment #0)
>
> The workaround, of course, is to define the empty default constructor in
> ConstMember.
Or simply add an empty new-initializer, which works when you can't change the
definition of ConstMember
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/48859] [4.6/4.7 Regression] incorrect "uninitialized const member" error on new without new-initializer
2011-05-03 23:56 [Bug c++/48859] New: Regression: incorrect "uninitialized const member" error on new without new-initializer jyasskin at gcc dot gnu.org
2011-05-04 0:03 ` [Bug c++/48859] " pinskia at gcc dot gnu.org
2011-05-04 12:35 ` [Bug c++/48859] [4.6/4.7 Regression] " redi at gcc dot gnu.org
@ 2011-05-04 12:36 ` redi at gcc dot gnu.org
2011-05-04 13:52 ` fabien at gcc dot gnu.org
` (6 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: redi at gcc dot gnu.org @ 2011-05-04 12:36 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48859
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |rejects-valid
Status|UNCONFIRMED |NEW
Last reconfirmed| |2011.05.04 12:32:05
CC| |fabien.chene at gmail dot
| |com
Summary|Regression: incorrect |[4.6/4.7 Regression]
|"uninitialized const |incorrect "uninitialized
|member" error on new |const member" error on new
|without new-initializer |without new-initializer
Ever Confirmed|0 |1
--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> 2011-05-04 12:32:05 UTC ---
Fabien, could you take a look? I think Andrew's right that this was caused by
the patch for PR 25811
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/48859] [4.6/4.7 Regression] incorrect "uninitialized const member" error on new without new-initializer
2011-05-03 23:56 [Bug c++/48859] New: Regression: incorrect "uninitialized const member" error on new without new-initializer jyasskin at gcc dot gnu.org
` (2 preceding siblings ...)
2011-05-04 12:36 ` redi at gcc dot gnu.org
@ 2011-05-04 13:52 ` fabien at gcc dot gnu.org
2011-05-09 17:52 ` fabien at gcc dot gnu.org
` (5 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: fabien at gcc dot gnu.org @ 2011-05-04 13:52 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48859
fabien at gcc dot gnu.org changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |fabien at gcc dot gnu.org
AssignedTo|unassigned at gcc dot |fabien at gcc dot gnu.org
|gnu.org |
--- Comment #4 from fabien at gcc dot gnu.org 2011-05-04 13:52:27 UTC ---
(In reply to comment #2)
> Fabien, could you take a look? I think Andrew's right that this was caused by
> the patch for PR 25811
Sure.
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/48859] [4.6/4.7 Regression] incorrect "uninitialized const member" error on new without new-initializer
2011-05-03 23:56 [Bug c++/48859] New: Regression: incorrect "uninitialized const member" error on new without new-initializer jyasskin at gcc dot gnu.org
` (3 preceding siblings ...)
2011-05-04 13:52 ` fabien at gcc dot gnu.org
@ 2011-05-09 17:52 ` fabien at gcc dot gnu.org
2011-05-09 18:28 ` redi at gcc dot gnu.org
` (4 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: fabien at gcc dot gnu.org @ 2011-05-09 17:52 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48859
--- Comment #5 from fabien at gcc dot gnu.org 2011-05-09 17:42:24 UTC ---
Author: fabien
Date: Mon May 9 17:42:21 2011
New Revision: 173583
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=173583
Log:
Fix PR C++/48859
Added:
trunk/gcc/testsuite/g++.dg/init/pr48859.C
Modified:
trunk/gcc/cp/ChangeLog
trunk/gcc/cp/init.c
trunk/gcc/testsuite/ChangeLog
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/48859] [4.6/4.7 Regression] incorrect "uninitialized const member" error on new without new-initializer
2011-05-03 23:56 [Bug c++/48859] New: Regression: incorrect "uninitialized const member" error on new without new-initializer jyasskin at gcc dot gnu.org
` (4 preceding siblings ...)
2011-05-09 17:52 ` fabien at gcc dot gnu.org
@ 2011-05-09 18:28 ` redi at gcc dot gnu.org
2011-05-10 8:27 ` fabien at gcc dot gnu.org
` (3 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: redi at gcc dot gnu.org @ 2011-05-09 18:28 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48859
--- Comment #6 from Jonathan Wakely <redi at gcc dot gnu.org> 2011-05-09 18:01:37 UTC ---
Thanks, Fabien!
N.B. the svn commit message should be the ChangeLog entry (look at the svn log
for any file to see what's normally done)
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/48859] [4.6/4.7 Regression] incorrect "uninitialized const member" error on new without new-initializer
2011-05-03 23:56 [Bug c++/48859] New: Regression: incorrect "uninitialized const member" error on new without new-initializer jyasskin at gcc dot gnu.org
` (5 preceding siblings ...)
2011-05-09 18:28 ` redi at gcc dot gnu.org
@ 2011-05-10 8:27 ` fabien at gcc dot gnu.org
2011-05-10 15:47 ` jyasskin at gcc dot gnu.org
` (2 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: fabien at gcc dot gnu.org @ 2011-05-10 8:27 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48859
fabien at gcc dot gnu.org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution| |FIXED
--- Comment #7 from fabien at gcc dot gnu.org 2011-05-10 08:15:17 UTC ---
(In reply to comment #6)
> Thanks, Fabien!
>
> N.B. the svn commit message should be the ChangeLog entry (look at the svn log
> for any file to see what's normally done)
Oups, sorry. I would be careful next time.
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/48859] [4.6/4.7 Regression] incorrect "uninitialized const member" error on new without new-initializer
2011-05-03 23:56 [Bug c++/48859] New: Regression: incorrect "uninitialized const member" error on new without new-initializer jyasskin at gcc dot gnu.org
` (6 preceding siblings ...)
2011-05-10 8:27 ` fabien at gcc dot gnu.org
@ 2011-05-10 15:47 ` jyasskin at gcc dot gnu.org
2011-05-10 16:38 ` fabien at gcc dot gnu.org
2011-05-11 7:54 ` fabien at gcc dot gnu.org
9 siblings, 0 replies; 11+ messages in thread
From: jyasskin at gcc dot gnu.org @ 2011-05-10 15:47 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48859
--- Comment #8 from Jeffrey Yasskin <jyasskin at gcc dot gnu.org> 2011-05-10 15:42:54 UTC ---
Thanks! Is this patch ok for the 4.6 branch too? If you don't have time to
backport it, I can.
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/48859] [4.6/4.7 Regression] incorrect "uninitialized const member" error on new without new-initializer
2011-05-03 23:56 [Bug c++/48859] New: Regression: incorrect "uninitialized const member" error on new without new-initializer jyasskin at gcc dot gnu.org
` (7 preceding siblings ...)
2011-05-10 15:47 ` jyasskin at gcc dot gnu.org
@ 2011-05-10 16:38 ` fabien at gcc dot gnu.org
2011-05-11 7:54 ` fabien at gcc dot gnu.org
9 siblings, 0 replies; 11+ messages in thread
From: fabien at gcc dot gnu.org @ 2011-05-10 16:38 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48859
--- Comment #9 from fabien at gcc dot gnu.org 2011-05-10 16:27:42 UTC ---
(In reply to comment #8)
> Thanks! Is this patch ok for the 4.6 branch too?
Yes, as it is a 4.6 regression, and Jason also approved it for 4.6.
> If you don't have time to backport it, I can.
I was planning to backport it this evening, thanks.
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/48859] [4.6/4.7 Regression] incorrect "uninitialized const member" error on new without new-initializer
2011-05-03 23:56 [Bug c++/48859] New: Regression: incorrect "uninitialized const member" error on new without new-initializer jyasskin at gcc dot gnu.org
` (8 preceding siblings ...)
2011-05-10 16:38 ` fabien at gcc dot gnu.org
@ 2011-05-11 7:54 ` fabien at gcc dot gnu.org
9 siblings, 0 replies; 11+ messages in thread
From: fabien at gcc dot gnu.org @ 2011-05-11 7:54 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48859
--- Comment #10 from fabien at gcc dot gnu.org 2011-05-11 06:03:42 UTC ---
Author: fabien
Date: Wed May 11 06:03:38 2011
New Revision: 173644
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=173644
Log:
gcc/cp/ChangeLog:
2011-05-11 Fabien Chene <fabien@gcc.gnu.org>
PR c++/48859
* init.c (diagnose_uninitialized_cst_or_ref_member_1): stop the
recursion if there is user defined constructor.
gcc/testsuite/ChangeLog:
2011-05-11 Fabien Chene <fabien@gcc.gnu.org>
PR c++/48859
* g++.dg/init/pr48859.C: New.
Added:
branches/gcc-4_6-branch/gcc/testsuite/g++.dg/init/pr48859.C
Modified:
branches/gcc-4_6-branch/gcc/cp/ChangeLog
branches/gcc-4_6-branch/gcc/cp/init.c
branches/gcc-4_6-branch/gcc/testsuite/ChangeLog
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2011-05-11 6:09 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-05-03 23:56 [Bug c++/48859] New: Regression: incorrect "uninitialized const member" error on new without new-initializer jyasskin at gcc dot gnu.org
2011-05-04 0:03 ` [Bug c++/48859] " pinskia at gcc dot gnu.org
2011-05-04 12:35 ` [Bug c++/48859] [4.6/4.7 Regression] " redi at gcc dot gnu.org
2011-05-04 12:36 ` redi at gcc dot gnu.org
2011-05-04 13:52 ` fabien at gcc dot gnu.org
2011-05-09 17:52 ` fabien at gcc dot gnu.org
2011-05-09 18:28 ` redi at gcc dot gnu.org
2011-05-10 8:27 ` fabien at gcc dot gnu.org
2011-05-10 15:47 ` jyasskin at gcc dot gnu.org
2011-05-10 16:38 ` fabien at gcc dot gnu.org
2011-05-11 7:54 ` fabien at gcc dot gnu.org
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).