public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/26698]  New: g++ accepts const-incorrect code due to conversion function
@ 2006-03-15 16:10 jkherciueh at gmx dot net
  2006-03-15 16:19 ` [Bug c++/26698] " pinskia at gcc dot gnu dot org
                   ` (19 more replies)
  0 siblings, 20 replies; 21+ messages in thread
From: jkherciueh at gmx dot net @ 2006-03-15 16:10 UTC (permalink / raw)
  To: gcc-bugs

/*
  The following piece of code should not compile:

  According to [12.3.2/1], the conversion function
  operator X&() cannot be called. However, its
  presence tricks the compiler into thinking that
  I has a license to initialize a non-const X& from a
  const X&. This is illegal by [8.5.3/5].

  I think that diagnostics is required in this case.

  Instead, g++ compiles this code, but the program
  segfaults.
*/

struct X {

  int x;

  X ( int i = 0 )
    : x ( i )
  {}

  operator X & ( void ) const {
    return ( *this );
  }

};

void add_one ( X & ref ) {
  ++ ref.x;
}

#include <iostream>

int main ( void ) {
  X const a ( 2 );
  add_one( a );
  std::cout << a.x << '\n';
}


-- 
           Summary: g++ accepts const-incorrect code due to conversion
                    function
           Product: gcc
           Version: 4.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: jkherciueh at gmx dot net


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


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

end of thread, other threads:[~2008-08-21 12:06 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-03-15 16:10 [Bug c++/26698] New: g++ accepts const-incorrect code due to conversion function jkherciueh at gmx dot net
2006-03-15 16:19 ` [Bug c++/26698] " pinskia at gcc dot gnu dot org
2006-05-26 15:37 ` bangerth at dealii dot org
2006-09-16  1:48 ` lopezibanez at gmail dot com
2006-09-16 21:14 ` lopezibanez at gmail dot com
2006-09-16 21:34 ` lopezibanez at gmail dot com
2006-09-16 21:50 ` [Bug c++/26698] [4.0/4.1/4.2 Regression] " pinskia at gcc dot gnu dot org
2006-09-20 21:58 ` mmitchel at gcc dot gnu dot org
2007-02-03 16:25 ` [Bug c++/26698] [4.0/4.1/4.2/4.3 " gdr at gcc dot gnu dot org
2007-02-03 17:27 ` jsm28 at gcc dot gnu dot org
2007-02-14  9:10 ` mmitchel at gcc dot gnu dot org
2007-09-07  0:34 ` pcarlini at suse dot de
2007-09-07  0:36 ` pcarlini at suse dot de
2007-09-07  0:39 ` pcarlini at suse dot de
2007-09-07 23:50 ` mmitchel at gcc dot gnu dot org
2007-10-02 15:47 ` pcarlini at suse dot de
2007-10-07 19:50 ` patchapp at dberlin dot org
2007-10-12 18:43 ` simartin at gcc dot gnu dot org
2007-10-13  6:05 ` simartin at gcc dot gnu dot org
2007-10-13  6:17 ` simartin at gcc dot gnu dot org
2008-08-21 12:06 ` paolo dot 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).