public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/15284] New: Access check on not-used copy-constructor
@ 2004-05-04 19:02 carlo at gcc dot gnu dot org
  2004-05-04 19:38 ` [Bug c++/15284] " pinskia at gcc dot gnu dot org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: carlo at gcc dot gnu dot org @ 2004-05-04 19:02 UTC (permalink / raw)
  To: gcc-bugs

Setting a copy constructor private is a well-known
way to make sure that it never is copied.  This usually
works fine - except in this case:

#include <iostream>

class A {
#ifdef COMPILEBUG
private:
#else
public:
#endif
  A(A const&)
  {
    std::cout << "Copy constructor is actually being used (called)!" << std::endl;
  }
public:
  A(int)
  {
    std::cout << "Calling A(int)" << std::endl;
  }
};

A f()
{
  return A(1);
}

int main()
{
  A a = f();
}


If you compile this without defining COMPILEBUG - then
it compiles fine of course.  And the output shows that
the copy constructor of A is never called!

>g++-cvs-3.5 test.cc
>a.out
Calling A(int)

Because the copy constructor is never called - one would
expect that it is ok to make it private; however:

>g++-cvs-3.5 -DCOMPILEBUG test.cc
test.cc: In function `A f()':
test.cc:10: error: `A::A(constA&)' is private
test.cc:22: error: within this context
test.cc:10: error: `A::A(constA&)' is private
test.cc:22: error: within this context
test.cc: In function `int main()':
test.cc:10: error: `A::A(constA&)' is private
test.cc:27: error: within this context
test.cc:10: error: `A::A(constA&)' is private
test.cc:27: error: within this context

The same behaviour is seen with all versions down to 2.95.2.

-- 
           Summary: Access check on not-used copy-constructor
           Product: gcc
           Version: 3.5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: carlo at gcc dot gnu dot org
                CC: gcc-bugs at gcc dot gnu dot org


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


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

* [Bug c++/15284] Access check on not-used copy-constructor
  2004-05-04 19:02 [Bug c++/15284] New: Access check on not-used copy-constructor carlo at gcc dot gnu dot org
@ 2004-05-04 19:38 ` pinskia at gcc dot gnu dot org
  2004-08-27  8:51 ` pinskia at gcc dot gnu dot org
  2004-08-27  8:51 ` pinskia at gcc dot gnu dot org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-05-04 19:38 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-05-04 19:38 -------
The copy constructor is need to be accessible even though it is not being called for this case.
See <http://gcc.gnu.org/bugs.html#cxx_rvalbind> and the reference standard sections.

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


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


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

* [Bug c++/15284] Access check on not-used copy-constructor
  2004-05-04 19:02 [Bug c++/15284] New: Access check on not-used copy-constructor carlo at gcc dot gnu dot org
  2004-05-04 19:38 ` [Bug c++/15284] " pinskia at gcc dot gnu dot org
  2004-08-27  8:51 ` pinskia at gcc dot gnu dot org
@ 2004-08-27  8:51 ` pinskia at gcc dot gnu dot org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-08-27  8:51 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-08-27 08:51 -------
Reopening bug to mark as a dup of ...

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


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


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

* [Bug c++/15284] Access check on not-used copy-constructor
  2004-05-04 19:02 [Bug c++/15284] New: Access check on not-used copy-constructor carlo at gcc dot gnu dot org
  2004-05-04 19:38 ` [Bug c++/15284] " pinskia at gcc dot gnu dot org
@ 2004-08-27  8:51 ` pinskia at gcc dot gnu dot org
  2004-08-27  8:51 ` pinskia at gcc dot gnu dot org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-08-27  8:51 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-08-27 08:51 -------
bug 12226.

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

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


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


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

end of thread, other threads:[~2004-08-27  8:51 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-05-04 19:02 [Bug c++/15284] New: Access check on not-used copy-constructor carlo at gcc dot gnu dot org
2004-05-04 19:38 ` [Bug c++/15284] " pinskia at gcc dot gnu dot org
2004-08-27  8:51 ` pinskia at gcc dot gnu dot org
2004-08-27  8:51 ` 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).