public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* Re: c++/3171: Copy constructor does not accept parameter by value
@ 2001-06-13 13:56 Ross Smith
  0 siblings, 0 replies; 3+ messages in thread
From: Ross Smith @ 2001-06-13 13:56 UTC (permalink / raw)
  To: nobody; +Cc: gcc-prs

The following reply was made to PR c++/3171; it has been noted by GNATS.

From: Ross Smith <ross.s@ihug.co.nz>
To: "Arun Saini , Gurgaon" <arun@ggn.hcltech.com>
Cc: gcc-gnats@gcc.gnu.org
Subject: Re: c++/3171: Copy constructor does not accept parameter by value
Date: Thu, 14 Jun 2001 08:52:57 +1200

 "Arun Saini , Gurgaon" wrote:
 > 
 > >Number:         3171
 > >Category:       c++
 > >Synopsis:       Copy constructor does not accept parameter by value
 
 Not a bug. Your assignment operator (not copy constructor, although that
 has the same problem) takes a non-const reference argumnt, and therefore
 can't accept a temporary on the RHS. (I'll grant you the error message
 is a trifle misleading, but I don't think that's going to be considered
 a high priority bug at this point.)
 
 -- 
 Ross Smith <ross.s@ihug.co.nz> The Internet Group, Auckland, New Zealand
 ========================================================================
         "Hungarian notation is the tactical nuclear weapon of
          source code obfuscation techniques." -- Roedy Green


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

* Re: c++/3171: Copy constructor does not accept parameter by value
@ 2001-06-13  9:36 Artem Khodush
  0 siblings, 0 replies; 3+ messages in thread
From: Artem Khodush @ 2001-06-13  9:36 UTC (permalink / raw)
  To: nobody; +Cc: gcc-prs

The following reply was made to PR c++/3171; it has been noted by GNATS.

From: "Artem Khodush" <artem@duma.gov.ru>
To: <gcc-gnats@gcc.gnu.org>
Cc:  
Subject: Re: c++/3171: Copy constructor does not accept parameter by value
Date: Wed, 13 Jun 2001 20:18:45 +0400

 Arun Saini , Gurgaon wrote: 
 > I am reproducing a portion of code and the error reported by the compiler
 > when I try to compile it.
 > 
 > 
 > Test someFunc(void)
 > {
 >   Test tempTest;
 >   tempTest.testVar = 10;
 > 
 >   return tempTest;
 > }
 > 
 > 
 > int main()
 > {
 >   Test t1;
 >   t1 = someFunc();
 >   return 0;
 > }
 > 
 
 This is not a bug. Here what's going on:
 the compiler created a temporary variable to store 
 the result of someFunc(), and you are trying to pass 
 that temporary to a copy constructor taking Test& 
 (without a const), which is not allowed in c++. 
 You have two options: either make Test::Test 
 copy constructor to take const Test& parameter, 
 or use the technique invented for std::auto_ptr
 to overcome this very problem (which is better 
 discussed elsewhere).
 
 
 
 


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

* c++/3171: Copy constructor does not accept parameter by value
@ 2001-06-13  8:16 Arun Saini, Gurgaon
  0 siblings, 0 replies; 3+ messages in thread
From: Arun Saini, Gurgaon @ 2001-06-13  8:16 UTC (permalink / raw)
  To: gcc-gnats

>Number:         3171
>Category:       c++
>Synopsis:       Copy constructor does not accept parameter by value
>Confidential:   no
>Severity:       critical
>Priority:       high
>Responsible:    unassigned
>State:          open
>Class:          rejects-legal
>Submitter-Id:   net
>Arrival-Date:   Wed Jun 13 08:16:00 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator:     Arun Saini
>Release:        3.0 20010528 (prerelease)
>Organization:
HCL Technologies, Gurgaon, INDIA
>Environment:
System: Linux ntc 2.2.16-22 #1 Tue Aug 22 16:49:06 EDT 2000 i686 unknown
Architecture: i686
host: i686-pc-linux-gnu
build: i686-pc-linux-gnu
target: i686-pc-linux-gnu
configured with: /usr/local/src/gcc-20010528/configure
--enable-threads=posix --enable-shared
>Description:
I am reproducing a portion of code and the error reported by the compiler
when I try to compile it.

class Test
{
  public :
    int testVar;

  Test()
  {
    testVar = 0;
  }

  Test(Test& t)
  {
    testVar = t.testVar;
    t.testVar = 0;
  }

  Test(Test *pt)
  {
    testVar = pt->testVar;
    pt -> testVar = 0;
  }

  Test& operator=(Test& t)
  {
    testVar = t.testVar;
    t.testVar = 0;
  }

  Test& operator=(Test* pt)
  {
    testVar = pt->testVar;
    pt->testVar = 0;
  }
};

Test someFunc(void)
{
  Test tempTest;
  tempTest.testVar = 10;

  return tempTest;
}


int main()
{
  Test t1;
  t1 = someFunc();
  return 0;
}

When I compile this the error given is

g++ test.cpp
test.cpp: In function `int main()':
test.cpp:49: no match for `Test& = Test' operator
test.cpp:24: candidates are: Test& Test::operator=(Test&)
test.cpp:30:                 Test& Test::operator=(Test*)

>How-To-Repeat:
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted:


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

end of thread, other threads:[~2001-06-13 13:56 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-06-13 13:56 c++/3171: Copy constructor does not accept parameter by value Ross Smith
  -- strict thread matches above, loose matches on Subject: below --
2001-06-13  9:36 Artem Khodush
2001-06-13  8:16 Arun Saini, Gurgaon

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