public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/18113] New: compiler allows 2 copy constructors
@ 2004-10-22 16:49 profvonsully at yahoo dot com
2004-10-22 16:53 ` [Bug c++/18113] " profvonsully at yahoo dot com
` (9 more replies)
0 siblings, 10 replies; 11+ messages in thread
From: profvonsully at yahoo dot com @ 2004-10-22 16:49 UTC (permalink / raw)
To: gcc-bugs
The bug is simple :
lets say :
"
class TObject;
typedef TObject& rObject;
class TObject
{
public:
TObject(){}
TObject(const TObject&);
TObject(const rObject);
};
TObject::TObject(const TObject&)
{
char*s;
s="constructor 1";
}
TObject::TObject(const rObject)
{
char*s;
s="constructor 2";
}
"
In da function:
"
TObject F()
{
TObject AnObject;
TObject anotherObject=AnObject;//constructor 2 !!!
return AnObject;
}
" constructor 2 will be called!
--
Summary: compiler allows 2 copy constructors
Product: gcc
Version: 3.3.2
Status: UNCONFIRMED
Severity: critical
Priority: P1
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: profvonsully at yahoo dot com
CC: gcc-bugs at gcc dot gnu dot org
GCC build triplet: i386
GCC host triplet: i386
GCC target triplet: i386
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18113
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/18113] compiler allows 2 copy constructors
2004-10-22 16:49 [Bug c++/18113] New: compiler allows 2 copy constructors profvonsully at yahoo dot com
@ 2004-10-22 16:53 ` profvonsully at yahoo dot com
2004-10-22 17:13 ` pinskia at gcc dot gnu dot org
` (8 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: profvonsully at yahoo dot com @ 2004-10-22 16:53 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From profvonsully at yahoo dot com 2004-10-22 16:53 -------
Created an attachment (id=7402)
--> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=7402&action=view)
html file describing the bug
no comment ;)
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18113
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/18113] compiler allows 2 copy constructors
2004-10-22 16:49 [Bug c++/18113] New: compiler allows 2 copy constructors profvonsully at yahoo dot com
2004-10-22 16:53 ` [Bug c++/18113] " profvonsully at yahoo dot com
@ 2004-10-22 17:13 ` pinskia at gcc dot gnu dot org
2004-10-22 18:54 ` bangerth at dealii dot org
` (7 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-10-22 17:13 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2004-10-22 17:13 -------
Not a bug. The "const" in "const rObject" is meaning less in this context (the rObject is already const,
references are const, what they refer to are not).
--
What |Removed |Added
----------------------------------------------------------------------------
Severity|critical |normal
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18113
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/18113] compiler allows 2 copy constructors
2004-10-22 16:49 [Bug c++/18113] New: compiler allows 2 copy constructors profvonsully at yahoo dot com
2004-10-22 16:53 ` [Bug c++/18113] " profvonsully at yahoo dot com
2004-10-22 17:13 ` pinskia at gcc dot gnu dot org
@ 2004-10-22 18:54 ` bangerth at dealii dot org
2004-10-26 18:41 ` profvonsully at yahoo dot com
` (6 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: bangerth at dealii dot org @ 2004-10-22 18:54 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From bangerth at dealii dot org 2004-10-22 18:53 -------
Your second copy constructor will be called every time the argument
given can't be bound to a reference. The code is perfectly legal, and
the compiler needs to accept it.
W.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18113
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/18113] compiler allows 2 copy constructors
2004-10-22 16:49 [Bug c++/18113] New: compiler allows 2 copy constructors profvonsully at yahoo dot com
` (2 preceding siblings ...)
2004-10-22 18:54 ` bangerth at dealii dot org
@ 2004-10-26 18:41 ` profvonsully at yahoo dot com
2004-10-26 18:44 ` pinskia at gcc dot gnu dot org
` (5 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: profvonsully at yahoo dot com @ 2004-10-26 18:41 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From profvonsully at yahoo dot com 2004-10-26 18:41 -------
there is another example for those that did not look at the attachment(sorry
for my initial language):
class TObject;
typedef TObject& rObject;
class TObject
{
public:
TObject(){}
TObject(const rObject){}//the compiler does NOT realize that this is
a copy constructor
// TObject(const TObject&){} the compiler wants this to be a copy
constructor
// "error: no matching function for call to
`TObject::TObject(TObject)'" :)))))))
//I am profvonsully@yahoo.com
};
TObject GetAnObject()
{
TObject AnObject;
return AnObject;
}
void HandleObject(TObject toj)
{
}
void errors_are_here()
{
HandleObject
(
GetAnObject()
);/*here g++ says an error exists*/
}
--
What |Removed |Added
----------------------------------------------------------------------------
Status|RESOLVED |UNCONFIRMED
Resolution|INVALID |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18113
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/18113] compiler allows 2 copy constructors
2004-10-22 16:49 [Bug c++/18113] New: compiler allows 2 copy constructors profvonsully at yahoo dot com
` (3 preceding siblings ...)
2004-10-26 18:41 ` profvonsully at yahoo dot com
@ 2004-10-26 18:44 ` pinskia at gcc dot gnu dot org
2004-10-26 18:45 ` profvonsully at yahoo dot com
` (4 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-10-26 18:44 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2004-10-26 18:44 -------
Read my comment again, this is not a bug.
--
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18113
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/18113] compiler allows 2 copy constructors
2004-10-22 16:49 [Bug c++/18113] New: compiler allows 2 copy constructors profvonsully at yahoo dot com
` (4 preceding siblings ...)
2004-10-26 18:44 ` pinskia at gcc dot gnu dot org
@ 2004-10-26 18:45 ` profvonsully at yahoo dot com
2004-10-26 18:48 ` pinskia at gcc dot gnu dot org
` (3 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: profvonsully at yahoo dot com @ 2004-10-26 18:45 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From profvonsully at yahoo dot com 2004-10-26 18:45 -------
(In reply to comment #2)
> look at the attahement !
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18113
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/18113] compiler allows 2 copy constructors
2004-10-22 16:49 [Bug c++/18113] New: compiler allows 2 copy constructors profvonsully at yahoo dot com
` (5 preceding siblings ...)
2004-10-26 18:45 ` profvonsully at yahoo dot com
@ 2004-10-26 18:48 ` pinskia at gcc dot gnu dot org
2004-10-26 19:05 ` profvonsully at yahoo dot com
` (2 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-10-26 18:48 UTC (permalink / raw)
To: gcc-bugs
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 238 bytes --]
------- Additional Comments From pinskia at gcc dot gnu dot org 2004-10-26 18:48 -------
TObject(const rObject){} is the same as TObject(TObject&){}
The const is ignored.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18113
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/18113] compiler allows 2 copy constructors
2004-10-22 16:49 [Bug c++/18113] New: compiler allows 2 copy constructors profvonsully at yahoo dot com
` (6 preceding siblings ...)
2004-10-26 18:48 ` pinskia at gcc dot gnu dot org
@ 2004-10-26 19:05 ` profvonsully at yahoo dot com
2004-10-26 19:21 ` profvonsully at yahoo dot com
2004-10-26 20:34 ` reichelt at gcc dot gnu dot org
9 siblings, 0 replies; 11+ messages in thread
From: profvonsully at yahoo dot com @ 2004-10-26 19:05 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From profvonsully at yahoo dot com 2004-10-26 19:05 -------
(In reply to comment #7
i dont care about the const . i descovered the bug in the first example of the
attcahment where the compiler prints an error that is not logic(in borland C++
i used TObject(rObject) with no problem).
If a fuction returns a TObject and I pass the result to a function that
receives a TObject an error ocurs !! pls make me understand this :)
--
What |Removed |Added
----------------------------------------------------------------------------
Status|RESOLVED |UNCONFIRMED
Resolution|INVALID |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18113
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/18113] compiler allows 2 copy constructors
2004-10-22 16:49 [Bug c++/18113] New: compiler allows 2 copy constructors profvonsully at yahoo dot com
` (7 preceding siblings ...)
2004-10-26 19:05 ` profvonsully at yahoo dot com
@ 2004-10-26 19:21 ` profvonsully at yahoo dot com
2004-10-26 20:34 ` reichelt at gcc dot gnu dot org
9 siblings, 0 replies; 11+ messages in thread
From: profvonsully at yahoo dot com @ 2004-10-26 19:21 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From profvonsully at yahoo dot com 2004-10-26 19:21 -------
!!!
in the second example only one constructor is writeed (to be compiled)
"TObject(rTObject)"!!(the other one is in a coment and ... errror)
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18113
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/18113] compiler allows 2 copy constructors
2004-10-22 16:49 [Bug c++/18113] New: compiler allows 2 copy constructors profvonsully at yahoo dot com
` (8 preceding siblings ...)
2004-10-26 19:21 ` profvonsully at yahoo dot com
@ 2004-10-26 20:34 ` reichelt at gcc dot gnu dot org
9 siblings, 0 replies; 11+ messages in thread
From: reichelt at gcc dot gnu dot org @ 2004-10-26 20:34 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From reichelt at gcc dot gnu dot org 2004-10-26 20:34 -------
Here's a detailed explanation of the second example:
You are calling the function "void HandleObject(TObject toj);" as follows:
"HandleObject( GetAnObject() );"
To do this you need a copy constructor to copy the result of
"GetAnObject()" into "toj".
The only copy constructor that is available is "TObject(const rObject)"
which is essentially "TObject(TObject&)" and not "TObject(const TObject&)"
as one might think (see comment #2).
However, "TObject(TObject&)" can only take an lvalue (something that can
be modified) as argument, but "GetAnObject()" only provides an lvalue
(which cannot be modified). Therefore, gcc correctly complains that it
cannot find a suitable copy constructor.
This is a bug in your code and not in gcc.
Note, that the compiler is allowed to optimize away the copy constructor.
Nevertheless, it has to check whether the copy constructor is present.
Alas, many compilers forgot to check this.
--
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18113
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2004-10-26 20:34 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-10-22 16:49 [Bug c++/18113] New: compiler allows 2 copy constructors profvonsully at yahoo dot com
2004-10-22 16:53 ` [Bug c++/18113] " profvonsully at yahoo dot com
2004-10-22 17:13 ` pinskia at gcc dot gnu dot org
2004-10-22 18:54 ` bangerth at dealii dot org
2004-10-26 18:41 ` profvonsully at yahoo dot com
2004-10-26 18:44 ` pinskia at gcc dot gnu dot org
2004-10-26 18:45 ` profvonsully at yahoo dot com
2004-10-26 18:48 ` pinskia at gcc dot gnu dot org
2004-10-26 19:05 ` profvonsully at yahoo dot com
2004-10-26 19:21 ` profvonsully at yahoo dot com
2004-10-26 20:34 ` reichelt 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).