public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* Re: c++/4696: Casting operator creates bogus temporary
@ 2002-04-26  5:05 nathan
  0 siblings, 0 replies; 2+ messages in thread
From: nathan @ 2002-04-26  5:05 UTC (permalink / raw)
  To: gcc-bugs, gcc-prs, nobody, sparker

Synopsis: Casting operator creates bogus temporary

State-Changed-From-To: open->closed
State-Changed-By: nathan
State-Changed-When: Fri Apr 26 05:05:11 2002
State-Changed-Why:
    fixed in 3.1

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=4696


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

* c++/4696: Casting operator creates bogus temporary
@ 2001-10-25 23:16 sparker
  0 siblings, 0 replies; 2+ messages in thread
From: sparker @ 2001-10-25 23:16 UTC (permalink / raw)
  To: gcc-gnats; +Cc: sparker

>Number:         4696
>Category:       c++
>Synopsis:       Casting operator creates bogus temporary
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          rejects-legal
>Submitter-Id:   net
>Arrival-Date:   Thu Oct 25 23:16:01 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator:     Steven Parker
>Release:        3.0.2
>Organization:
University of Utah
>Environment:
System: Linux ufo.cs.utah.edu 2.4.8-pre3-xfs #22 Thu Oct 18 14:10:22 MDT 2001 i686 unknown
Architecture: i686

	
host: i686-pc-linux-gnu
build: i686-pc-linux-gnu
target: i686-pc-linux-gnu
configured with: ../gcc-3.0.2/configure --prefix=/usr --enable-languages=c++,f77
>Description:

gcc 3.0 and 3.0.2 attempt to produce an unnecessary copy when using
a casting operator.  gcc 2.95 did not have this problem, and other
C++ compilers accept this code.

Here is a simple example:

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

class B : public A {
public:
  B() {}
private:
  B(const B&);
};

class C {
  B b;
public:
  operator B&() {return b;}
};

void foo1(const B& b)
{
}

void foo2(const A& a)
{
}

main()
{
  A a;
  foo2(a); // Good
  B b;
  foo1(b); // Good
  foo2(b); // Good
  C c;
  foo1(c); // Good
  foo2(c); // Bad: gcc complains about private copy ctor in B
  foo2(static_cast<B&>(c)); // Workaround
};

The line marked Bad: complains on gcc 3.0.* that the copy
ctor for B is private, which is true.  However, the copy ctor
for B should never be needed - a temporary object is not needed
in this case.

This code compiles under gcc 2.9x, SGI MIPSpro 7.3.1.1m, and
Compaq C++ V6.3-008.

	
>How-To-Repeat:
   g++ -o t t.cc
>Fix:
        Workaround is an explicit cast (yuck)
>Release-Note:
>Audit-Trail:
>Unformatted:


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

end of thread, other threads:[~2002-04-26 12:05 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-04-26  5:05 c++/4696: Casting operator creates bogus temporary nathan
  -- strict thread matches above, loose matches on Subject: below --
2001-10-25 23:16 sparker

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