public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/25811] No failure creating a POD containing a const member, using new without a new-initializer.
       [not found] <bug-25811-4@http.gcc.gnu.org/bugzilla/>
@ 2012-05-24 22:46 ` paolo.carlini at oracle dot com
  0 siblings, 0 replies; 14+ messages in thread
From: paolo.carlini at oracle dot com @ 2012-05-24 22:46 UTC (permalink / raw)
  To: gcc-bugs

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

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|gcc-bugs at gcc dot gnu.org |
         Resolution|                            |FIXED
      Known to fail|                            |

--- Comment #14 from Paolo Carlini <paolo.carlini at oracle dot com> 2012-05-24 22:36:47 UTC ---
So this fixed, I think already in 4.6.0.


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug c++/25811] No failure creating a POD containing a const member, using new without a new-initializer.
  2006-01-16 20:00 [Bug c++/25811] New: " fabien dot chene at laposte dot net
                   ` (11 preceding siblings ...)
  2010-03-31 13:53 ` redi at gcc dot gnu dot org
@ 2010-04-12 19:58 ` jason at gcc dot gnu dot org
  12 siblings, 0 replies; 14+ messages in thread
From: jason at gcc dot gnu dot org @ 2010-04-12 19:58 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #13 from jason at gcc dot gnu dot org  2010-04-12 19:58 -------
Subject: Bug 25811

Author: jason
Date: Mon Apr 12 19:58:27 2010
New Revision: 158239

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=158239
Log:
        PR c++/25811
        * cp-tree.h (diagnose_uninitialized_cst_or_ref_member): Declare.
        * init.c (build_new_1): Check for uninitialized const members and
        uninitialized reference members, when using new without
        new-initializer. Call diagnose_uninitialized_cst_or_ref_member.
        (diagnose_uninitialized_cst_or_ref_member): Define, call
        diagnose_uninitialized_cst_or_ref_member_1.
        (diagnose_uninitialized_cst_or_ref_member_1): New function.

Added:
    trunk/gcc/testsuite/g++.dg/init/pr25811.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/cp-tree.h
    trunk/gcc/cp/init.c
    trunk/gcc/testsuite/ChangeLog


-- 


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


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug c++/25811] No failure creating a POD containing a const member, using new without a new-initializer.
  2006-01-16 20:00 [Bug c++/25811] New: " fabien dot chene at laposte dot net
                   ` (10 preceding siblings ...)
  2010-03-31 13:46 ` fabien dot chene at gmail dot com
@ 2010-03-31 13:53 ` redi at gcc dot gnu dot org
  2010-04-12 19:58 ` jason at gcc dot gnu dot org
  12 siblings, 0 replies; 14+ messages in thread
From: redi at gcc dot gnu dot org @ 2010-03-31 13:53 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #12 from redi at gcc dot gnu dot org  2010-03-31 13:52 -------
That works for me, although I should point out I can't approve the patch, so
it's just my opinion


-- 


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


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug c++/25811] No failure creating a POD containing a const member, using new without a new-initializer.
  2006-01-16 20:00 [Bug c++/25811] New: " fabien dot chene at laposte dot net
                   ` (9 preceding siblings ...)
  2010-03-31 12:34 ` redi at gcc dot gnu dot org
@ 2010-03-31 13:46 ` fabien dot chene at gmail dot com
  2010-03-31 13:53 ` redi at gcc dot gnu dot org
  2010-04-12 19:58 ` jason at gcc dot gnu dot org
  12 siblings, 0 replies; 14+ messages in thread
From: fabien dot chene at gmail dot com @ 2010-03-31 13:46 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #11 from fabien dot chene at gmail dot com  2010-03-31 13:46 -------
(In reply to comment #10)
> Thanks. I can't test it now but that looks better.
> 
> Just below your new code I see this error:
> 
>     error ("uninitialized const in %<new%> of %q#T", elt_type);
> 
> Maybe your new diagnostics should also include 'new' like that.

Would 'error ("uninitialized const member in %q#T using %<new%>", elt_type)'
suit you ?


-- 


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


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug c++/25811] No failure creating a POD containing a const member, using new without a new-initializer.
  2006-01-16 20:00 [Bug c++/25811] New: " fabien dot chene at laposte dot net
                   ` (8 preceding siblings ...)
  2010-03-31 12:21 ` fabien dot chene at gmail dot com
@ 2010-03-31 12:34 ` redi at gcc dot gnu dot org
  2010-03-31 13:46 ` fabien dot chene at gmail dot com
                   ` (2 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: redi at gcc dot gnu dot org @ 2010-03-31 12:34 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #10 from redi at gcc dot gnu dot org  2010-03-31 12:34 -------
Thanks. I can't test it now but that looks better.

Just below your new code I see this error:

    error ("uninitialized const in %<new%> of %q#T", elt_type);

Maybe your new diagnostics should also include 'new' like that.


-- 


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


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug c++/25811] No failure creating a POD containing a const member, using new without a new-initializer.
  2006-01-16 20:00 [Bug c++/25811] New: " fabien dot chene at laposte dot net
                   ` (7 preceding siblings ...)
  2010-03-31  8:55 ` redi at gcc dot gnu dot org
@ 2010-03-31 12:21 ` fabien dot chene at gmail dot com
  2010-03-31 12:34 ` redi at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: fabien dot chene at gmail dot com @ 2010-03-31 12:21 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #9 from fabien dot chene at gmail dot com  2010-03-31 12:20 -------
(In reply to comment #8)
> (N.B. your email to gcc-patches gives the wrong PR number in the subject.)
> 
> This reject the following valid program:
> 
> struct X {
>   X() : c(0), r(c) {}
>   const int c;
>   int const& r;
> };
> 
> int main()
> {
>   new X;
> }
> 
> If there is a default constructor it will be called, and so the members will
> not be uninitialized.

OK, I've revised the patch to check for a user defined constructor.
I have also added your testcase, and others dealing with arrays.

http://gcc.gnu.org/ml/gcc-patches/2010-03/msg01486.html


-- 


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


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug c++/25811] No failure creating a POD containing a const member, using new without a new-initializer.
  2006-01-16 20:00 [Bug c++/25811] New: " fabien dot chene at laposte dot net
                   ` (6 preceding siblings ...)
  2010-03-31  7:07 ` fabien dot chene at gmail dot com
@ 2010-03-31  8:55 ` redi at gcc dot gnu dot org
  2010-03-31 12:21 ` fabien dot chene at gmail dot com
                   ` (4 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: redi at gcc dot gnu dot org @ 2010-03-31  8:55 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #8 from redi at gcc dot gnu dot org  2010-03-31 08:55 -------
(N.B. your email to gcc-patches gives the wrong PR number in the subject.)

This reject the following valid program:

struct X {
  X() : c(0), r(c) {}
  const int c;
  int const& r;
};

int main()
{
  new X;
}

If there is a default constructor it will be called, and so the members will
not be uninitialized.


-- 


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


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug c++/25811] No failure creating a POD containing a const member, using new without a new-initializer.
  2006-01-16 20:00 [Bug c++/25811] New: " fabien dot chene at laposte dot net
                   ` (5 preceding siblings ...)
  2010-03-30 11:19 ` redi at gcc dot gnu dot org
@ 2010-03-31  7:07 ` fabien dot chene at gmail dot com
  2010-03-31  8:55 ` redi at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: fabien dot chene at gmail dot com @ 2010-03-31  7:07 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from fabien dot chene at gmail dot com  2010-03-31 07:06 -------
(In reply to comment #6)
> (In reply to comment #5)
> > > Nevertheless, can you confirm that it is valid C++03 ?
> > 
> > I mean invalid, sorry.
> 
> Yup :-)
> 
> It is invalid.  A is a non-POD class type, so 5.3.4/15 says the new-expression
> without a new-initializer causes the object to be default-initialized, which
> causes a default constructor to be implicitly-defined with an empty
> mem-initializer list (12.1/7) which is ill-formed by 8.5/5 because the
> reference member is not initialized.
> 
> 
> In C++03 the cases of Foo and A are slightly different, "new Foo" is ill-formed
> according to 5.3.4/15 and "new A" is ill-formed as described above.

Thanks for the clarification !
Patch here for the non C++0X part: 
http://gcc.gnu.org/ml/gcc-patches/2010-03/msg01467.html

> In C++0x both "new Foo" and "new A" result in a call to a deleted constructor.


-- 


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


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug c++/25811] No failure creating a POD containing a const member, using new without a new-initializer.
  2006-01-16 20:00 [Bug c++/25811] New: " fabien dot chene at laposte dot net
                   ` (4 preceding siblings ...)
  2010-03-30 10:10 ` fabien dot chene at gmail dot com
@ 2010-03-30 11:19 ` redi at gcc dot gnu dot org
  2010-03-31  7:07 ` fabien dot chene at gmail dot com
                   ` (6 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: redi at gcc dot gnu dot org @ 2010-03-30 11:19 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from redi at gcc dot gnu dot org  2010-03-30 11:19 -------
(In reply to comment #5)
> > Nevertheless, can you confirm that it is valid C++03 ?
> 
> I mean invalid, sorry.

Yup :-)

It is invalid.  A is a non-POD class type, so 5.3.4/15 says the new-expression
without a new-initializer causes the object to be default-initialized, which
causes a default constructor to be implicitly-defined with an empty
mem-initializer list (12.1/7) which is ill-formed by 8.5/5 because the
reference member is not initialized.


In C++03 the cases of Foo and A are slightly different, "new Foo" is ill-formed
according to 5.3.4/15 and "new A" is ill-formed as described above.

In C++0x both "new Foo" and "new A" result in a call to a deleted constructor.


-- 


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


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug c++/25811] No failure creating a POD containing a const member, using new without a new-initializer.
  2006-01-16 20:00 [Bug c++/25811] New: " fabien dot chene at laposte dot net
                   ` (3 preceding siblings ...)
  2010-03-30 10:07 ` fabien dot chene at gmail dot com
@ 2010-03-30 10:10 ` fabien dot chene at gmail dot com
  2010-03-30 11:19 ` redi at gcc dot gnu dot org
                   ` (7 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: fabien dot chene at gmail dot com @ 2010-03-30 10:10 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from fabien dot chene at gmail dot com  2010-03-30 10:10 -------

> Nevertheless, can you confirm that it is valid C++03 ?

I mean invalid, sorry.


-- 


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


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug c++/25811] No failure creating a POD containing a const member, using new without a new-initializer.
  2006-01-16 20:00 [Bug c++/25811] New: " fabien dot chene at laposte dot net
                   ` (2 preceding siblings ...)
  2010-03-30  9:16 ` redi at gcc dot gnu dot org
@ 2010-03-30 10:07 ` fabien dot chene at gmail dot com
  2010-03-30 10:10 ` fabien dot chene at gmail dot com
                   ` (8 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: fabien dot chene at gmail dot com @ 2010-03-30 10:07 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from fabien dot chene at gmail dot com  2010-03-30 10:07 -------
(In reply to comment #3)
> (In reply to comment #2)
> > is it still invalid in c++0X ?
> 
> Yes.
> 
> > 5.3.4.15 has been revamped, and I no longer find a motif to reject such code.
> 
> In C++0x the object is default-initialized, which for a class type means the
> default constructor is called.  In this code, the default constructor is
> deleted, so the code will not compile. See 12.1/5

OK thanks.

> > I think the following code is also invalid, according to 8.5.6 (c++03) / 8.5.8
> > (c++0x):
> > 
> > struct A { int& i; };
> > void f () { new A; }
> 
> Not quite: in C++0x the program doesn't call for default-initialization of
> A::i, it calls for default-initialization of A, which is invalid because the
> default constructor is deleted.

OK, but it appears that the C++0X part is not yet implemented in GCC -- the
constructor is not deleted in this case.
Nevertheless, can you confirm that it is valid C++03 ?


-- 


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


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug c++/25811] No failure creating a POD containing a const member, using new without a new-initializer.
  2006-01-16 20:00 [Bug c++/25811] New: " fabien dot chene at laposte dot net
  2006-01-16 20:06 ` [Bug c++/25811] " pinskia at gcc dot gnu dot org
  2010-03-30  8:22 ` fabien dot chene at gmail dot com
@ 2010-03-30  9:16 ` redi at gcc dot gnu dot org
  2010-03-30 10:07 ` fabien dot chene at gmail dot com
                   ` (9 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: redi at gcc dot gnu dot org @ 2010-03-30  9:16 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from redi at gcc dot gnu dot org  2010-03-30 09:16 -------
(In reply to comment #2)
> is it still invalid in c++0X ?

Yes.

> 5.3.4.15 has been revamped, and I no longer find a motif to reject such code.

In C++0x the object is default-initialized, which for a class type means the
default constructor is called.  In this code, the default constructor is
deleted, so the code will not compile. See 12.1/5

> I think the following code is also invalid, according to 8.5.6 (c++03) / 8.5.8
> (c++0x):
> 
> struct A { int& i; };
> void f () { new A; }

Not quite: in C++0x the program doesn't call for default-initialization of
A::i, it calls for default-initialization of A, which is invalid because the
default constructor is deleted.


-- 


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


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug c++/25811] No failure creating a POD containing a const member, using new without a new-initializer.
  2006-01-16 20:00 [Bug c++/25811] New: " fabien dot chene at laposte dot net
  2006-01-16 20:06 ` [Bug c++/25811] " pinskia at gcc dot gnu dot org
@ 2010-03-30  8:22 ` fabien dot chene at gmail dot com
  2010-03-30  9:16 ` redi at gcc dot gnu dot org
                   ` (10 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: fabien dot chene at gmail dot com @ 2010-03-30  8:22 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from fabien dot chene at gmail dot com  2010-03-30 08:22 -------
is it still invalid in c++0X ?
5.3.4.15 has been revamped, and I no longer find a motif to reject such code.

I think the following code is also invalid, according to 8.5.6 (c++03) / 8.5.8
(c++0x):

struct A { int& i; };
void f () { new A; }

I have a patch to fix both issues.


-- 


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


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug c++/25811] No failure creating a POD containing a const member, using new without a new-initializer.
  2006-01-16 20:00 [Bug c++/25811] New: " fabien dot chene at laposte dot net
@ 2006-01-16 20:06 ` pinskia at gcc dot gnu dot org
  2010-03-30  8:22 ` fabien dot chene at gmail dot com
                   ` (11 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-01-16 20:06 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from pinskia at gcc dot gnu dot org  2006-01-16 20:06 -------
Confirmed, not a regression.


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
           Keywords|                            |accepts-invalid
      Known to fail|                            |2.95.3 3.3.1 3.0.4 3.4.0
                   |                            |4.0.0 4.1.0 4.2.0
   Last reconfirmed|0000-00-00 00:00:00         |2006-01-16 20:06:02
               date|                            |


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


^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2012-05-24 22:37 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-25811-4@http.gcc.gnu.org/bugzilla/>
2012-05-24 22:46 ` [Bug c++/25811] No failure creating a POD containing a const member, using new without a new-initializer paolo.carlini at oracle dot com
2006-01-16 20:00 [Bug c++/25811] New: " fabien dot chene at laposte dot net
2006-01-16 20:06 ` [Bug c++/25811] " pinskia at gcc dot gnu dot org
2010-03-30  8:22 ` fabien dot chene at gmail dot com
2010-03-30  9:16 ` redi at gcc dot gnu dot org
2010-03-30 10:07 ` fabien dot chene at gmail dot com
2010-03-30 10:10 ` fabien dot chene at gmail dot com
2010-03-30 11:19 ` redi at gcc dot gnu dot org
2010-03-31  7:07 ` fabien dot chene at gmail dot com
2010-03-31  8:55 ` redi at gcc dot gnu dot org
2010-03-31 12:21 ` fabien dot chene at gmail dot com
2010-03-31 12:34 ` redi at gcc dot gnu dot org
2010-03-31 13:46 ` fabien dot chene at gmail dot com
2010-03-31 13:53 ` redi at gcc dot gnu dot org
2010-04-12 19:58 ` jason at gcc dot gnu dot 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).