public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/63654] New: An explicit copy constructor should be used in the second step of a class copy-initialization.
@ 2014-10-27  9:39 kariya_mitsuru at hotmail dot com
  2014-10-27  9:57 ` [Bug c++/63654] " redi at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: kariya_mitsuru at hotmail dot com @ 2014-10-27  9:39 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 63654
           Summary: An explicit copy constructor should be used in the
                    second step of a class copy-initialization.
           Product: gcc
           Version: 5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: kariya_mitsuru at hotmail dot com

Created attachment 33815
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=33815&action=edit
gcc -v

The sample code below should be compiled successfully but it causes a
compilation error by gcc.

======== sample code =======
struct S {
    explicit S(const S&) {}
    S(int) {}
};

int main()
{
    S s = 1;
}
============================
===================== compiler output ====================================
prog.cc: In function 'int main()':
prog.cc:8:11: error: no matching function for call to 'S::S(S)'
    S s = 1;
          ^
prog.cc:3:5: note: candidate: S::S(int)
    S(int) {}
    ^
prog.cc:3:5: note:   no known conversion for argument 1 from 'S' to 'int'
prog.cc:3:5: note:   after user-defined conversion: S::S(int)
===================== compiler output ====================================
cf. http://melpon.org/wandbox/permlink/fA27PoaI9y9q2Xz6

C++ standard [dcl.init]/p.17.6.2 says that

... The result of the call (which is the temporary for the constructor case) is
then used to direct-initialize, according to the rules above, the object that
is the destination of the copy-initialization. ...

I think that the variable "s" should be *direct-initialize* from the result of
the call "S(int)", so the explicit copy constructor "explicit S(const S&)"
should be used.
(at least if the option "-pedantic-errors" is specified)


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

* [Bug c++/63654] An explicit copy constructor should be used in the second step of a class copy-initialization.
  2014-10-27  9:39 [Bug c++/63654] New: An explicit copy constructor should be used in the second step of a class copy-initialization kariya_mitsuru at hotmail dot com
@ 2014-10-27  9:57 ` redi at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: redi at gcc dot gnu.org @ 2014-10-27  9:57 UTC (permalink / raw)
  To: gcc-bugs

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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

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

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
duplicate

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


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

end of thread, other threads:[~2014-10-27  9:57 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-10-27  9:39 [Bug c++/63654] New: An explicit copy constructor should be used in the second step of a class copy-initialization kariya_mitsuru at hotmail dot com
2014-10-27  9:57 ` [Bug c++/63654] " redi at gcc dot gnu.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).