public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/29043]  New: Constructor for POD type with const member without member initializer accepted
@ 2006-09-12 21:02 amylaar at gcc dot gnu dot org
  2006-09-13  3:00 ` [Bug c++/29043] " fang at csl dot cornell dot edu
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: amylaar at gcc dot gnu dot org @ 2006-09-12 21:02 UTC (permalink / raw)
  To: gcc-bugs

The following C++ code should not compile:

class C
{
  C() { }
  struct s {
    const int i;
  };
};


The C++ standard clause 12.6.2 ; 4 says that for each non-static data
member of a POD class type containing a member of a const-qualified type, there
must be a member initialiser, or else the program is ill-formed.


-- 
           Summary: Constructor for POD type with const member without
                    member initializer accepted
           Product: gcc
           Version: 4.2.0
            Status: UNCONFIRMED
          Keywords: accepts-invalid
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: amylaar at gcc dot gnu dot org


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


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

* [Bug c++/29043] Constructor for POD type with const member without member initializer accepted
  2006-09-12 21:02 [Bug c++/29043] New: Constructor for POD type with const member without member initializer accepted amylaar at gcc dot gnu dot org
@ 2006-09-13  3:00 ` fang at csl dot cornell dot edu
  2006-09-13  9:23 ` andrew dot stubbs at st dot com
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: fang at csl dot cornell dot edu @ 2006-09-13  3:00 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from fang at csl dot cornell dot edu  2006-09-13 03:00 -------
As you've written it, class C doesn't have any non-static members.  Struct C::s
hasn't been declared as a member object of C.  const int i is a member of C::s,
not C, so C() without member initializers should be acceptable.  

Note, if you write just :

struct s {
  const int i;
};

// This, however, doesn't give any diagnostics until an instance of s is
declared.  

s foo;

struct.cc:7: error: structure 'foo' with uninitialized const members

Now, I'd need to lookup the standard to determine whether or not a diagnostic
is appropriate...


-- 

fang at csl dot cornell dot edu changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |fang at csl dot cornell dot
                   |                            |edu


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


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

* [Bug c++/29043] Constructor for POD type with const member without member initializer accepted
  2006-09-12 21:02 [Bug c++/29043] New: Constructor for POD type with const member without member initializer accepted amylaar at gcc dot gnu dot org
  2006-09-13  3:00 ` [Bug c++/29043] " fang at csl dot cornell dot edu
@ 2006-09-13  9:23 ` andrew dot stubbs at st dot com
  2006-09-13 16:10 ` bangerth at dealii dot org
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: andrew dot stubbs at st dot com @ 2006-09-13  9:23 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from andrew dot stubbs at st dot com  2006-09-13 09:23 -------
(In reply to comment #1)
> As you've written it, class C doesn't have any non-static members.  Struct C::s
> hasn't been declared as a member object of C.  const int i is a member of C::s,
> not C, so C() without member initializers should be acceptable.  

How about this example:

struct S {
  const int i;
};

class C
{
public:
  C() { }    
  S s;
};

void f()
{
  C c;
  S s;
}

This fails at the line `S s;' in f(), but the `C c;' line is accepted silently.

The standard says the requirement applies to data-members *containing* a member
of const-qualified type.


-- 


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


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

* [Bug c++/29043] Constructor for POD type with const member without member initializer accepted
  2006-09-12 21:02 [Bug c++/29043] New: Constructor for POD type with const member without member initializer accepted amylaar at gcc dot gnu dot org
  2006-09-13  3:00 ` [Bug c++/29043] " fang at csl dot cornell dot edu
  2006-09-13  9:23 ` andrew dot stubbs at st dot com
@ 2006-09-13 16:10 ` bangerth at dealii dot org
  2010-04-19 20:03 ` fabien dot chene at gmail dot com
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: bangerth at dealii dot org @ 2006-09-13 16:10 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from bangerth at dealii dot org  2006-09-13 16:10 -------
Confirmed with the testcase from attachment #2.


-- 

bangerth at dealii dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bangerth at dealii dot org
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
   Last reconfirmed|0000-00-00 00:00:00         |2006-09-13 16:10:45
               date|                            |


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


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

* [Bug c++/29043] Constructor for POD type with const member without member initializer accepted
  2006-09-12 21:02 [Bug c++/29043] New: Constructor for POD type with const member without member initializer accepted amylaar at gcc dot gnu dot org
                   ` (2 preceding siblings ...)
  2006-09-13 16:10 ` bangerth at dealii dot org
@ 2010-04-19 20:03 ` fabien dot chene at gmail dot com
  2010-04-20 22:47 ` fabien dot chene at gmail dot com
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: fabien dot chene at gmail dot com @ 2010-04-19 20:03 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from fabien dot chene at gmail dot com  2010-04-19 20:03 -------
mine ...


-- 


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


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

* [Bug c++/29043] Constructor for POD type with const member without member initializer accepted
  2006-09-12 21:02 [Bug c++/29043] New: Constructor for POD type with const member without member initializer accepted amylaar at gcc dot gnu dot org
                   ` (3 preceding siblings ...)
  2010-04-19 20:03 ` fabien dot chene at gmail dot com
@ 2010-04-20 22:47 ` fabien dot chene at gmail dot com
  2010-04-21  9:46 ` redi at gcc dot gnu dot org
  2010-04-28  0:03 ` jason at gcc dot gnu dot org
  6 siblings, 0 replies; 8+ messages in thread
From: fabien dot chene at gmail dot com @ 2010-04-20 22:47 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from fabien dot chene at gmail dot com  2010-04-20 22:47 -------
patch here:
http://gcc.gnu.org/ml/gcc-patches/2010-04/msg01269.html


-- 


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


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

* [Bug c++/29043] Constructor for POD type with const member without member initializer accepted
  2006-09-12 21:02 [Bug c++/29043] New: Constructor for POD type with const member without member initializer accepted amylaar at gcc dot gnu dot org
                   ` (4 preceding siblings ...)
  2010-04-20 22:47 ` fabien dot chene at gmail dot com
@ 2010-04-21  9:46 ` redi at gcc dot gnu dot org
  2010-04-28  0:03 ` jason at gcc dot gnu dot org
  6 siblings, 0 replies; 8+ messages in thread
From: redi at gcc dot gnu dot org @ 2010-04-21  9:46 UTC (permalink / raw)
  To: gcc-bugs



-- 

redi at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |fabien dot chene at gmail
                   |dot org                     |dot com
             Status|NEW                         |ASSIGNED


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


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

* [Bug c++/29043] Constructor for POD type with const member without member initializer accepted
  2006-09-12 21:02 [Bug c++/29043] New: Constructor for POD type with const member without member initializer accepted amylaar at gcc dot gnu dot org
                   ` (5 preceding siblings ...)
  2010-04-21  9:46 ` redi at gcc dot gnu dot org
@ 2010-04-28  0:03 ` jason at gcc dot gnu dot org
  6 siblings, 0 replies; 8+ messages in thread
From: jason at gcc dot gnu dot org @ 2010-04-28  0:03 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from jason at gcc dot gnu dot org  2010-04-28 00:03 -------
Subject: Bug 29043

Author: jason
Date: Wed Apr 28 00:03:21 2010
New Revision: 158817

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=158817
Log:
        PR c++/29043
        * init.c (perform_member_init): check for uninitialized const or
        reference members, including array types.

Added:
    trunk/gcc/testsuite/g++.dg/init/pr29043.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/init.c
    trunk/gcc/testsuite/ChangeLog


-- 


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


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

end of thread, other threads:[~2010-04-28  0:03 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-09-12 21:02 [Bug c++/29043] New: Constructor for POD type with const member without member initializer accepted amylaar at gcc dot gnu dot org
2006-09-13  3:00 ` [Bug c++/29043] " fang at csl dot cornell dot edu
2006-09-13  9:23 ` andrew dot stubbs at st dot com
2006-09-13 16:10 ` bangerth at dealii dot org
2010-04-19 20:03 ` fabien dot chene at gmail dot com
2010-04-20 22:47 ` fabien dot chene at gmail dot com
2010-04-21  9:46 ` redi at gcc dot gnu dot org
2010-04-28  0:03 ` 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).