public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/57758] New: gcc accepts incorrect in-class brace initializers
@ 2013-06-29 19:22 lundberj at gmail dot com
  2013-06-29 20:26 ` [Bug c++/57758] " paolo.carlini at oracle dot com
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: lundberj at gmail dot com @ 2013-06-29 19:22 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 57758
           Summary: gcc accepts incorrect in-class brace initializers
           Product: gcc
           Version: 4.8.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: lundberj at gmail dot com

In summary, having a class member in-class copy-construct from itself (!)
compiles without warning when curly-brace syntax is used.

The result is that the class invariants are never established. The following
code is accepted: 

#include <iostream>
struct C{
   C()=delete;
   C(const C& other): x(other.x+1){}
   int x=10;
};
struct D{
   C c0{c0};  // << -- compiles without warning
 //C c1{c1};  // << -- correctly rejected
};
int main(){
   D d;
   std::cout << d.c0.x << std::endl; // prints 1
}

You already get the point. Similarly, these definitions of C also compiles, and
the printed value of x is 0 in both cases.

struct C{
   int x=10;  
   C(float,float){}
};
struct C{
   int x=10;  
};

Using the following definition I get an un-initialized reference: x == 1412476
:

struct C{
   C(const C& other): z(other.z),x(other.x){}
   int z=10;
   int & x{z};
};

This seems like something that would be good to detect.

Using class C{}; is correctly rejected (with 'too many initializers for ‘C’').
>From gcc-bugs-return-425438-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Sat Jun 29 19:32:47 2013
Return-Path: <gcc-bugs-return-425438-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 21238 invoked by alias); 29 Jun 2013 19:32:47 -0000
Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm
Precedence: bulk
List-Id: <gcc-bugs.gcc.gnu.org>
List-Archive: <http://gcc.gnu.org/ml/gcc-bugs/>
List-Post: <mailto:gcc-bugs@gcc.gnu.org>
List-Help: <mailto:gcc-bugs-help@gcc.gnu.org>
Sender: gcc-bugs-owner@gcc.gnu.org
Delivered-To: mailing list gcc-bugs@gcc.gnu.org
Received: (qmail 21201 invoked by uid 48); 29 Jun 2013 19:32:44 -0000
From: "mikpe at it dot uu.se" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/57719] [4.8/4.9 Regression] wrong code at -O3 on x86_64-linux-gnu
Date: Sat, 29 Jun 2013 19:32:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: tree-optimization
X-Bugzilla-Version: 4.9.0
X-Bugzilla-Keywords:
X-Bugzilla-Severity: normal
X-Bugzilla-Who: mikpe at it dot uu.se
X-Bugzilla-Status: NEW
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org
X-Bugzilla-Target-Milestone: 4.8.2
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields:
Message-ID: <bug-57719-4-CSyVF7mHyL@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-57719-4@http.gcc.gnu.org/bugzilla/>
References: <bug-57719-4@http.gcc.gnu.org/bugzilla/>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 7bit
X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/
Auto-Submitted: auto-generated
MIME-Version: 1.0
X-SW-Source: 2013-06/txt/msg01817.txt.bz2
Content-length: 296

http://gcc.gnu.org/bugzilla/show_bug.cgi?idW719

--- Comment #4 from Mikael Pettersson <mikpe at it dot uu.se> ---
(In reply to Zhendong Su from comment #2)
> test #3: wrong code from gcc trunk (but not gcc 4.8) at -O3 in 32-bit mode
> only:

The wrong-code for test #3 started with r198121.


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

* [Bug c++/57758] gcc accepts incorrect in-class brace initializers
  2013-06-29 19:22 [Bug c++/57758] New: gcc accepts incorrect in-class brace initializers lundberj at gmail dot com
@ 2013-06-29 20:26 ` paolo.carlini at oracle dot com
  2013-06-29 23:24 ` lundberj at gmail dot com
  2014-11-23 14:58 ` paolo.carlini at oracle dot com
  2 siblings, 0 replies; 4+ messages in thread
From: paolo.carlini at oracle dot com @ 2013-06-29 20:26 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |diagnostic
                 CC|                            |paolo.carlini at oracle dot com

--- Comment #1 from Paolo Carlini <paolo.carlini at oracle dot com> ---
Frankly, I doubt this issue adds new information beyond what we have got
already in Bugzilla, eg PR52167 & co.


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

* [Bug c++/57758] gcc accepts incorrect in-class brace initializers
  2013-06-29 19:22 [Bug c++/57758] New: gcc accepts incorrect in-class brace initializers lundberj at gmail dot com
  2013-06-29 20:26 ` [Bug c++/57758] " paolo.carlini at oracle dot com
@ 2013-06-29 23:24 ` lundberj at gmail dot com
  2014-11-23 14:58 ` paolo.carlini at oracle dot com
  2 siblings, 0 replies; 4+ messages in thread
From: lundberj at gmail dot com @ 2013-06-29 23:24 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Johan Lundberg <lundberj at gmail dot com> ---
Yes. I'm sorry, it's almost word-for-word identical to 48483.


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

* [Bug c++/57758] gcc accepts incorrect in-class brace initializers
  2013-06-29 19:22 [Bug c++/57758] New: gcc accepts incorrect in-class brace initializers lundberj at gmail dot com
  2013-06-29 20:26 ` [Bug c++/57758] " paolo.carlini at oracle dot com
  2013-06-29 23:24 ` lundberj at gmail dot com
@ 2014-11-23 14:58 ` paolo.carlini at oracle dot com
  2 siblings, 0 replies; 4+ messages in thread
From: paolo.carlini at oracle dot com @ 2014-11-23 14:58 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57758

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |DUPLICATE

--- Comment #3 from Paolo Carlini <paolo.carlini at oracle dot com> ---
Dup then.

*** This bug has been marked as a duplicate of bug 48483 ***


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

end of thread, other threads:[~2014-11-23 14:58 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-06-29 19:22 [Bug c++/57758] New: gcc accepts incorrect in-class brace initializers lundberj at gmail dot com
2013-06-29 20:26 ` [Bug c++/57758] " paolo.carlini at oracle dot com
2013-06-29 23:24 ` lundberj at gmail dot com
2014-11-23 14:58 ` paolo.carlini at oracle dot com

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).