public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/43127] Inconsistent and odd constructor calls.
       [not found] <bug-43127-4@http.gcc.gnu.org/bugzilla/>
@ 2024-03-16 19:32 ` pinskia at gcc dot gnu.org
  0 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-03-16 19:32 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=43127

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

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

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
First note C++17+ changed the rules so using C++17 allows this to compile,
guaranteed copy elision
(https://en.cppreference.com/w/cpp/language/copy_elision) so no copy is
required or even tried.

Second, the code is in fact invalid C++98/03/11/14 .

To make it valid C++11/14, you can use the rvalue reference instead for the
constructor:
auto_ptr(auto_ptr<type>&& source)

For valid C++98, you could add a constructor which takes a const reference
which allows binding a temporary to it:
auto_ptr(const auto_ptr<type>& source)

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

* [Bug c++/43127] Inconsistent and odd constructor calls.
  2010-02-20  6:33 [Bug c++/43127] New: Inconsistant " stvwooddell at embarqmail dot com
  2010-02-20 14:01 ` [Bug c++/43127] Inconsistent " rguenth at gcc dot gnu dot org
  2010-02-20 18:01 ` stvwooddell at embarqmail dot com
@ 2010-02-20 18:13 ` stvwooddell at embarqmail dot com
  2 siblings, 0 replies; 4+ messages in thread
From: stvwooddell at embarqmail dot com @ 2010-02-20 18:13 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from stvwooddell at embarqmail dot com  2010-02-20 18:13 -------
Scratch that, that's a error from a file that shouldn't even exist. Copied the
given code to a clean project and it compiled. So bug, but a miscommunication
in that the constructor is being implicitly add so that the original form is
trying to pass a anonymous object as a argument to the implicitly added
constructor, which is calling the protected typecast operator.

Still, that leaves the issue that the following has two different behaviours
when they are logically the same. I'm sure this is just a failure on my part to
understand the standard, where is that covered?

ptr Ret(new object(*this));
return Ret;

return Ret(new object(*this));


-- 


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


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

* [Bug c++/43127] Inconsistent and odd constructor calls.
  2010-02-20  6:33 [Bug c++/43127] New: Inconsistant " stvwooddell at embarqmail dot com
  2010-02-20 14:01 ` [Bug c++/43127] Inconsistent " rguenth at gcc dot gnu dot org
@ 2010-02-20 18:01 ` stvwooddell at embarqmail dot com
  2010-02-20 18:13 ` stvwooddell at embarqmail dot com
  2 siblings, 0 replies; 4+ messages in thread
From: stvwooddell at embarqmail dot com @ 2010-02-20 18:01 UTC (permalink / raw)
  To: gcc-bugs

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1139 bytes --]



------- Comment #2 from stvwooddell at embarqmail dot com  2010-02-20 18:01 -------
This compiles for you?

                virtual ptr clone () const
                {
                        return new object(*this);
                }

gives me the error that a function matching the copy constructor does not
exist:

n file included from ../objects/map.cpp:27:
../objects/../include/object.hpp: In member function ‘virtual auto_ptr<object>
object::clone() const’:
../objects/../include/object.hpp:80: error: no matching function for call to
‘auto_ptr<object>::auto_ptr(auto_ptr<object>)’
../objects/../include/global.hpp:73: note: candidates are:
auto_ptr<type>::auto_ptr(auto_ptr<type>&) [with type = object]
../objects/../include/global.hpp:71: note:                
auto_ptr<type>::auto_ptr(type*) [with type = object]
make: *** [objects/map.o] Error 1

It is my understanding that all the forms should work by creating a (anonymous)
object, then call the copy constructor passing that object as it's only
argument.

In what gcc version or configuration does it work?


-- 


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


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

* [Bug c++/43127] Inconsistent and odd constructor calls.
  2010-02-20  6:33 [Bug c++/43127] New: Inconsistant " stvwooddell at embarqmail dot com
@ 2010-02-20 14:01 ` rguenth at gcc dot gnu dot org
  2010-02-20 18:01 ` stvwooddell at embarqmail dot com
  2010-02-20 18:13 ` stvwooddell at embarqmail dot com
  2 siblings, 0 replies; 4+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2010-02-20 14:01 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from rguenth at gcc dot gnu dot org  2010-02-20 14:00 -------
You can even use

                virtual ptr clone () const
                {
                        return new object(*this);
                }


-- 


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


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

end of thread, other threads:[~2024-03-16 19:32 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-43127-4@http.gcc.gnu.org/bugzilla/>
2024-03-16 19:32 ` [Bug c++/43127] Inconsistent and odd constructor calls pinskia at gcc dot gnu.org
2010-02-20  6:33 [Bug c++/43127] New: Inconsistant " stvwooddell at embarqmail dot com
2010-02-20 14:01 ` [Bug c++/43127] Inconsistent " rguenth at gcc dot gnu dot org
2010-02-20 18:01 ` stvwooddell at embarqmail dot com
2010-02-20 18:13 ` stvwooddell at embarqmail dot com

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