public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/57155] New: casting to const reference error
@ 2013-05-03  7:34 rockeet at gmail dot com
  2013-05-03  9:04 ` [Bug c++/57155] " redi at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: rockeet at gmail dot com @ 2013-05-03  7:34 UTC (permalink / raw)
  To: gcc-bugs


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

             Bug #: 57155
           Summary: casting to const reference error
    Classification: Unclassified
           Product: gcc
           Version: 4.7.2
            Status: UNCONFIRMED
          Severity: major
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: rockeet@gmail.com


#include <assert.h>
int main() {
    const char* buf = "12345678";
    const int& cref = (const int&)buf[0];
    const int&  ref = (      int&)buf[0];
    assert(cref == ref);
    return 0;
}

// Above assertion failed on g++4.1.2, g++4.4.6, g++4.7.1 and g++4.7.2
// These are all my tested g++ version
// cref just got first byte of buf


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

* [Bug c++/57155] casting to const reference error
  2013-05-03  7:34 [Bug c++/57155] New: casting to const reference error rockeet at gmail dot com
@ 2013-05-03  9:04 ` redi at gcc dot gnu.org
  2013-05-03  9:08 ` redi at gcc dot gnu.org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: redi at gcc dot gnu.org @ 2013-05-03  9:04 UTC (permalink / raw)
  To: gcc-bugs


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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|major                       |normal


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

* [Bug c++/57155] casting to const reference error
  2013-05-03  7:34 [Bug c++/57155] New: casting to const reference error rockeet at gmail dot com
  2013-05-03  9:04 ` [Bug c++/57155] " redi at gcc dot gnu.org
@ 2013-05-03  9:08 ` redi at gcc dot gnu.org
  2013-05-03 10:35 ` rockeet at gmail dot com
  2013-05-03 10:51 ` redi at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: redi at gcc dot gnu.org @ 2013-05-03  9:08 UTC (permalink / raw)
  To: gcc-bugs


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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

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

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> 2013-05-03 09:08:03 UTC ---
    const int& cref = (const int&)buf[0];

This creates a temporary of type int, initialized with buf[0], and binds a
reference to it, the same as:

    const int& cref = int(buf[0]);

So it's correct that it has the same value as buf[0].


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

* [Bug c++/57155] casting to const reference error
  2013-05-03  7:34 [Bug c++/57155] New: casting to const reference error rockeet at gmail dot com
  2013-05-03  9:04 ` [Bug c++/57155] " redi at gcc dot gnu.org
  2013-05-03  9:08 ` redi at gcc dot gnu.org
@ 2013-05-03 10:35 ` rockeet at gmail dot com
  2013-05-03 10:51 ` redi at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: rockeet at gmail dot com @ 2013-05-03 10:35 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #2 from rockeet <rockeet at gmail dot com> 2013-05-03 10:35:53 UTC ---
In this case, C++ shouldn't create a temporal object and bound the const ref to
it. The C++ standard (C++11) says:

5.2.1
Subscripting
[expr.sub]
1
A postfix expression followed by an expression in square brackets is a postfix
expression. One of the expres-
sions shall have the type “pointer to T” and the other shall have unscoped
enumeration or integral type.
The result is an lvalue of type “T.” The type “T” shall be a completely-defined
object type.61The expression
E1[E2] is identical (by definition) to *((E1)+(E2)) [Note: see 5.3 and 5.7 for
details of * and + and 8.3.4
for details of arrays. —end note ]

5.3.1
Unary operators
[expr.unary.op]
1
The unary * operator performs indirection: the expression to which it is
applied shall be a pointer to an
object type, or a pointer to a function type and the result is an lvalue
referring to the object or function
to which the expression points. If the type of the expression is “pointer to
T,” the type of the result is “T.”
[Note: a pointer to an incomplete type (other than cv void) can be
dereferenced. The lvalue thus obtained
can be used in limited ways (to initialize a reference, for example); this
lvalue must not be converted to a
prvalue, see 4.1. —end note ]

5.4
Explicit type conversion (cast notation)
[expr.cast]
1
The result of the expression (T) cast-expression is of type T. The result is an
lvalue if T is an lvalue reference
type or an rvalue reference to function type and an xvalue if T is an rvalue
reference to object type; otherwise
the result is a prvalue. [Note: if T is a non-class type that is cv-qualified,
the cv-qualifiers are ignored when
determining the type of the resulting prvalue; see 3.10. —end note ]
>From gcc-bugs-return-421513-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Fri May 03 10:36:07 2013
Return-Path: <gcc-bugs-return-421513-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 22817 invoked by alias); 3 May 2013 10:36:07 -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 22286 invoked by uid 48); 3 May 2013 10:36:01 -0000
From: "redi at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug libstdc++/54577] deque<T>::erase() still takes iterator instead of const_iterator
Date: Fri, 03 May 2013 10:36:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: libstdc++
X-Bugzilla-Keywords:
X-Bugzilla-Severity: normal
X-Bugzilla-Who: redi at gcc dot gnu.org
X-Bugzilla-Status: UNCONFIRMED
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org
X-Bugzilla-Target-Milestone: ---
X-Bugzilla-Changed-Fields: CC
Message-ID: <bug-54577-4-yvczqvwk6i@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-54577-4@http.gcc.gnu.org/bugzilla/>
References: <bug-54577-4@http.gcc.gnu.org/bugzilla/>
X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/
Auto-Submitted: auto-generated
Content-Type: text/plain; charset="UTF-8"
MIME-Version: 1.0
X-SW-Source: 2013-05/txt/msg00186.txt.bz2
Content-length: 530


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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |mattyclarkson at gmail dot
                   |                            |com

--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> 2013-05-03 10:36:00 UTC ---
*** Bug 57158 has been marked as a duplicate of this bug. ***


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

* [Bug c++/57155] casting to const reference error
  2013-05-03  7:34 [Bug c++/57155] New: casting to const reference error rockeet at gmail dot com
                   ` (2 preceding siblings ...)
  2013-05-03 10:35 ` rockeet at gmail dot com
@ 2013-05-03 10:51 ` redi at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: redi at gcc dot gnu.org @ 2013-05-03 10:51 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> 2013-05-03 10:51:10 UTC ---
Keep reading 5.4, you didn't get to the bit about type conversions.


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

end of thread, other threads:[~2013-05-03 10:51 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-05-03  7:34 [Bug c++/57155] New: casting to const reference error rockeet at gmail dot com
2013-05-03  9:04 ` [Bug c++/57155] " redi at gcc dot gnu.org
2013-05-03  9:08 ` redi at gcc dot gnu.org
2013-05-03 10:35 ` rockeet at gmail dot com
2013-05-03 10:51 ` redi 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).