public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/12591] New: gcc accepts invalid code
@ 2003-10-12 20:45 hg211 at ural2 dot hszk dot bme dot hu
  2003-10-13  1:41 ` [Bug c++/12591] " pinskia at gcc dot gnu dot org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: hg211 at ural2 dot hszk dot bme dot hu @ 2003-10-12 20:45 UTC (permalink / raw)
  To: gcc-bugs

PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

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

           Summary: gcc accepts invalid code
           Product: gcc
           Version: 3.4
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: hg211 at ural2 dot hszk dot bme dot hu
                CC: gcc-bugs at gcc dot gnu dot org

gcc version 3.3.2 20030908 (Debian prerelease)
and
gcc version 3.4 20031005 (experimental)

accept this invalid code (it's invalid because the copy-constructor is
inaccessible):

class foo {
	private:
		foo(const foo &);
	public:
		foo();
};

const foo &bar = foo();


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

* [Bug c++/12591] gcc accepts invalid code
  2003-10-12 20:45 [Bug c++/12591] New: gcc accepts invalid code hg211 at ural2 dot hszk dot bme dot hu
@ 2003-10-13  1:41 ` pinskia at gcc dot gnu dot org
  2003-10-13 10:46 ` hg211 at ural2 dot hszk dot bme dot hu
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2003-10-13  1:41 UTC (permalink / raw)
  To: gcc-bugs

PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

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


pinskia at gcc dot gnu dot org changed:

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


------- Additional Comments From pinskia at gcc dot gnu dot org  2003-10-13 01:41 -------
Not invalid code because the copy-constructor is not needed for this case, only the constructor 
that takes no arguments because bar is "const foo&".


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

* [Bug c++/12591] gcc accepts invalid code
  2003-10-12 20:45 [Bug c++/12591] New: gcc accepts invalid code hg211 at ural2 dot hszk dot bme dot hu
  2003-10-13  1:41 ` [Bug c++/12591] " pinskia at gcc dot gnu dot org
@ 2003-10-13 10:46 ` hg211 at ural2 dot hszk dot bme dot hu
  2003-10-13 11:21 ` falk at debian dot org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: hg211 at ural2 dot hszk dot bme dot hu @ 2003-10-13 10:46 UTC (permalink / raw)
  To: gcc-bugs

PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

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



------- Additional Comments From hg211 at ural2 dot hszk dot bme dot hu  2003-10-13 10:46 -------
the standard says (in 8.5.3p5):

"If the initializer expression is an rvalue with T2 a class type and "cv1/T1" is
reference-compatible with "cv2/T2" the reference is bound in one of the
following ways (the choice is implementation defined):
  - The reference is bound to the object represented by the rvalue (see 3.10) or
to a sub-object within that object
  - A temporary of type "cv1/T2" [sic] is created, and a constructor is called
to copy the entire rvalue object into the temporary. The reference is bound to
the temporary or to a sub-object within the temporary

The constructor that would be used to make to copy shall be available whether or
not the copy is actually done."

I think it's about the copy constructor. If I'm not mistaken, the posted code is
invalid according to this quote (although I can't really see the rationale
behind it).


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

* [Bug c++/12591] gcc accepts invalid code
  2003-10-12 20:45 [Bug c++/12591] New: gcc accepts invalid code hg211 at ural2 dot hszk dot bme dot hu
  2003-10-13  1:41 ` [Bug c++/12591] " pinskia at gcc dot gnu dot org
  2003-10-13 10:46 ` hg211 at ural2 dot hszk dot bme dot hu
@ 2003-10-13 11:21 ` falk at debian dot org
  2003-10-13 13:53 ` hg211 at ural2 dot hszk dot bme dot hu
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: falk at debian dot org @ 2003-10-13 11:21 UTC (permalink / raw)
  To: gcc-bugs

PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

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



------- Additional Comments From falk at debian dot org  2003-10-13 11:21 -------
Compaq's compiler says this when enabling strict ANSI mode:

cxx: Warning: test.cc, line 8: "foo::foo(const foo &)", required for copy that
          was eliminated, is inaccessible
const foo &bar = foo();
-----------------^

So it is not invalid because the copy was eliminated, which to do the compiler
is allowed.

Maybe we could modify this to a low priority warning request for something
similar.


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

* [Bug c++/12591] gcc accepts invalid code
  2003-10-12 20:45 [Bug c++/12591] New: gcc accepts invalid code hg211 at ural2 dot hszk dot bme dot hu
                   ` (2 preceding siblings ...)
  2003-10-13 11:21 ` falk at debian dot org
@ 2003-10-13 13:53 ` hg211 at ural2 dot hszk dot bme dot hu
  2003-10-13 15:58 ` pinskia at gcc dot gnu dot org
  2003-10-14 16:39 ` pinskia at gcc dot gnu dot org
  5 siblings, 0 replies; 7+ messages in thread
From: hg211 at ural2 dot hszk dot bme dot hu @ 2003-10-13 13:53 UTC (permalink / raw)
  To: gcc-bugs

PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

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



------- Additional Comments From hg211 at ural2 dot hszk dot bme dot hu  2003-10-13 13:53 -------
Not really. The code is still invalid (it doesn't matter whether the function
call eliminated or not). Consider this:

class foo {
	public:
		foo(foo &);
		foo();
};

const foo &bar = foo();

Here, the compiler had to eliminate a function call to a function which doesn't
exist. So Compaq's compiler is wrong too: it's not a warning, but an error.
Although it's not a serious error :)


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

* [Bug c++/12591] gcc accepts invalid code
  2003-10-12 20:45 [Bug c++/12591] New: gcc accepts invalid code hg211 at ural2 dot hszk dot bme dot hu
                   ` (3 preceding siblings ...)
  2003-10-13 13:53 ` hg211 at ural2 dot hszk dot bme dot hu
@ 2003-10-13 15:58 ` pinskia at gcc dot gnu dot org
  2003-10-14 16:39 ` pinskia at gcc dot gnu dot org
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2003-10-13 15:58 UTC (permalink / raw)
  To: gcc-bugs

PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

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


pinskia at gcc dot gnu dot org changed:

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


------- Additional Comments From pinskia at gcc dot gnu dot org  2003-10-13 15:58 -------
Reopening based on the standard.


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

* [Bug c++/12591] gcc accepts invalid code
  2003-10-12 20:45 [Bug c++/12591] New: gcc accepts invalid code hg211 at ural2 dot hszk dot bme dot hu
                   ` (4 preceding siblings ...)
  2003-10-13 15:58 ` pinskia at gcc dot gnu dot org
@ 2003-10-14 16:39 ` pinskia at gcc dot gnu dot org
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2003-10-14 16:39 UTC (permalink / raw)
  To: gcc-bugs

PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

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


pinskia at gcc dot gnu dot org changed:

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


------- Additional Comments From pinskia at gcc dot gnu dot org  2003-10-14 16:39 -------
This is a dup of bug 12226.

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


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

end of thread, other threads:[~2003-10-14 16:39 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-10-12 20:45 [Bug c++/12591] New: gcc accepts invalid code hg211 at ural2 dot hszk dot bme dot hu
2003-10-13  1:41 ` [Bug c++/12591] " pinskia at gcc dot gnu dot org
2003-10-13 10:46 ` hg211 at ural2 dot hszk dot bme dot hu
2003-10-13 11:21 ` falk at debian dot org
2003-10-13 13:53 ` hg211 at ural2 dot hszk dot bme dot hu
2003-10-13 15:58 ` pinskia at gcc dot gnu dot org
2003-10-14 16:39 ` pinskia 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).