public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* Re: c++/9748: c++ using "operator = ( const Foo& )" when it *should* use "operator = ( int )"
@ 2003-02-18 20:27 bangerth
0 siblings, 0 replies; 2+ messages in thread
From: bangerth @ 2003-02-18 20:27 UTC (permalink / raw)
To: gcc-bugs, gcc-prs, nobody, royce3
Synopsis: c++ using "operator = ( const Foo& )" when it *should* use "operator = ( int )"
State-Changed-From-To: open->closed
State-Changed-By: bangerth
State-Changed-When: Tue Feb 18 20:27:53 2003
State-Changed-Why:
Not a bug.
If you use the assignment for
Foo foo = 1;
then a conversion constructor and a copy constructor needs
to be accessible (the compiler is allowed to elide the
temporary, though).
In strict ISO mode, Intel's icc also agrees:
tmp/g> icc -Xc -ansi x.cc
x.cc(36): warning #734: "Foo::Foo(const Foo &)", required for copy that was eliminated, is inaccessible
Foo foo = returnsInt();
^
What you quote about temporaries has nothing to do with
this.
W.
http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=9748
^ permalink raw reply [flat|nested] 2+ messages in thread
* c++/9748: c++ using "operator = ( const Foo& )" when it *should* use "operator = ( int )"
@ 2003-02-18 19:56 royce3
0 siblings, 0 replies; 2+ messages in thread
From: royce3 @ 2003-02-18 19:56 UTC (permalink / raw)
To: gcc-gnats
>Number: 9748
>Category: c++
>Synopsis: c++ using "operator = ( const Foo& )" when it *should* use "operator = ( int )"
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: rejects-legal
>Submitter-Id: net
>Arrival-Date: Tue Feb 18 19:56:00 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator: royce3@ev1.net
>Release: gcc version 3.2 (Mandrake Linux 9.0 3.2-1mdk)
>Organization:
>Environment:
>Description:
GCC is creating a temporary object and trying to use the
private copy constructor when there are several more appropriate selections.
$ g++ testcase.cpp
testcase.cpp: In function `int main()':
testcase.cpp:28: `Foo::Foo(const Foo&)' is private
testcase.cpp:39: within this context
testcase.cpp:39: initializing temporary from result of `Foo::Foo(int)'
>How-To-Repeat:
$ g++ testcase.cpp
// testcase.cpp
#include <stdio.h>
class Foo
{
int _i;
public:
Foo() : _i(0)
{
}
Foo ( int i ) : _i(i)
{
}
const Foo& operator = ( int i )
{
_i = i;
return *this;
}
// operator int() const
// {
// return _i;
// }
private:
// disable copy semantics
Foo ( const Foo& ) { }
const Foo& operator = ( const Foo& ) { return *this; }
};
int returnsInt()
{
return 7;
}
int main()
{
Foo foo = returnsInt();
}
// end of testcase.cpp
>Fix:
If GCC has an option to use a function which does not require the creation of a temporary object, it should do so.
>Release-Note:
>Audit-Trail:
>Unformatted:
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2003-02-18 20:27 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-02-18 20:27 c++/9748: c++ using "operator = ( const Foo& )" when it *should* use "operator = ( int )" bangerth
-- strict thread matches above, loose matches on Subject: below --
2003-02-18 19:56 royce3
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).