public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/66392] New: rejects-valid: copy-initialization through user-defined conversion sequence fails
@ 2015-06-03  8:24 filip.roseen at gmail dot com
  2015-08-04 14:54 ` [Bug c++/66392] " paolo at gcc dot gnu.org
  2015-08-04 14:55 ` paolo.carlini at oracle dot com
  0 siblings, 2 replies; 3+ messages in thread
From: filip.roseen at gmail dot com @ 2015-06-03  8:24 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 66392
           Summary: rejects-valid: copy-initialization through
                    user-defined conversion sequence fails
           Product: gcc
           Version: 5.1.0
            Status: UNCONFIRMED
          Keywords: rejects-valid
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: filip.roseen at gmail dot com
  Target Milestone: ---

Created attachment 35687
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=35687&action=edit
testcase.cpp - inaccurately rejected

There are many variants of the supplied testcase, but the following shall
compile due to the wording of `[dcl.init]p17` (and relevant sections) - `gcc`
inaccurately rejects the snippet:

    struct B { };

    struct A { 
      explicit A (A const&);
               A (B const&);
    };  

    int main () {
      A x = B {}; // legal
    }   

---------------

    testcase.cpp: In function ‘int main()’:
    testcase.cpp:9:12: error: no matching function for call to ‘A::A(A)’
       A x = B {}; // legal
                ^
    testcase.cpp:5:12: note: candidate: A::A(const B&)
                A (B const&);
                ^
    testcase.cpp:5:12: note:   no known conversion for argument 1 from ‘A’ to
‘const B&’
    testcase.cpp:5:12: note:   after user-defined conversion: A::A(const B&)

---------------

[ Note: `msvc`, `clang`, `icc` all accept the above snippet ]

---------------

In short the ISO C++ Standard says that if copy-initialization takes place
where the source type is not the same as the destination type, but there is a
user-defined conversion sequence that can convert the source type into the
destination type - such will be used to construct a temporary, and that
temporary will then be used to _direct-initialize_ the destination object.

It should be noted, as directly addressed in the standard wording, that
copy-elision may be used to skip the construction of the temporary object.

[ Note: it is important to note that the wording talks about "user-defined
conversion sequences", as such one must properly take into account usage of
`operator T`, where `T` is the destination type, in the source type which shall
yield the same described behavior as the attached testcase ]

------------------------------------------

Relevant part of `[dcl.init]p17`:

> Otherwise (i.e., for the remaining copy-initialization cases), user-defined
> conversion sequences that can convert from the source type to the destination
> type or (when a conversion function is used) to a derived class thereof are
> enumerated as described in [over.match.copy], and the best one is chosen through
> overload resolution ([over.match]). If the conversion cannot be done or is
> ambiguous, the initialization is ill-formed. The function selected is called
> with the initializer expression as its argument; if the function is a
> constructor, the call initializes a temporary of the cv-unqualified version of
> the destination type. The temporary is a prvalue. 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. In certain cases, an implementation is permitted to
> eliminate the copying inherent in this direct-initialization by constructing the
> intermediate result directly into the object being initialized; see
> [class.temporary], [class.copy]
>From gcc-bugs-return-487932-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Wed Jun 03 08:25:26 2015
Return-Path: <gcc-bugs-return-487932-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 51545 invoked by alias); 3 Jun 2015 08:25:26 -0000
Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm
Precedence: bulk
List-Id: <gcc-bugs.gcc.gnu.org>
List-Archive: <http://gcc.gnu.org/ml/gcc-bugs/>
List-Post: <mailto:gcc-bugs@gcc.gnu.org>
List-Help: <mailto:gcc-bugs-help@gcc.gnu.org>
Sender: gcc-bugs-owner@gcc.gnu.org
Delivered-To: mailing list gcc-bugs@gcc.gnu.org
Received: (qmail 51390 invoked by uid 55); 3 Jun 2015 08:25:22 -0000
From: "mpolacek at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c/29358] Warning issued two times with snprintf
Date: Wed, 03 Jun 2015 08:25:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: c
X-Bugzilla-Version: 4.1.2
X-Bugzilla-Keywords: diagnostic
X-Bugzilla-Severity: normal
X-Bugzilla-Who: mpolacek at gcc dot gnu.org
X-Bugzilla-Status: NEW
X-Bugzilla-Resolution:
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org
X-Bugzilla-Target-Milestone: ---
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields:
Message-ID: <bug-29358-4-xC4U9zUyDo@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-29358-4@http.gcc.gnu.org/bugzilla/>
References: <bug-29358-4@http.gcc.gnu.org/bugzilla/>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 7bit
X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/
Auto-Submitted: auto-generated
MIME-Version: 1.0
X-SW-Source: 2015-06/txt/msg00264.txt.bz2
Content-length: 699

https://gcc.gnu.org/bugzilla/show_bug.cgi?id)358

--- Comment #8 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Author: mpolacek
Date: Wed Jun  3 08:24:50 2015
New Revision: 224062

URL: https://gcc.gnu.org/viewcvs?rev"4062&root=gcc&view=rev
Log:
        PR c/64223
        PR c/29358
        * tree.c (attribute_value_equal): Handle attribute format.
        (cmp_attrib_identifiers): Factor out of lookup_ident_attribute.

        * gcc.dg/pr64223-1.c: New test.
        * gcc.dg/pr64223-2.c: New test.

Added:
    trunk/gcc/testsuite/gcc.dg/pr64223-1.c
    trunk/gcc/testsuite/gcc.dg/pr64223-2.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/tree.c


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

* [Bug c++/66392] rejects-valid: copy-initialization through user-defined conversion sequence fails
  2015-06-03  8:24 [Bug c++/66392] New: rejects-valid: copy-initialization through user-defined conversion sequence fails filip.roseen at gmail dot com
@ 2015-08-04 14:54 ` paolo at gcc dot gnu.org
  2015-08-04 14:55 ` paolo.carlini at oracle dot com
  1 sibling, 0 replies; 3+ messages in thread
From: paolo at gcc dot gnu.org @ 2015-08-04 14:54 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from paolo at gcc dot gnu.org <paolo at gcc dot gnu.org> ---
Author: paolo
Date: Tue Aug  4 14:54:07 2015
New Revision: 226579

URL: https://gcc.gnu.org/viewcvs?rev=226579&root=gcc&view=rev
Log:
2015-08-04  Paolo Carlini  <paolo.carlini@oracle.com>

        PR c++/66392
        * g++.dg/init/explicit4.C: New.

Added:
    trunk/gcc/testsuite/g++.dg/init/explicit4.C
Modified:
    trunk/gcc/testsuite/ChangeLog


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

* [Bug c++/66392] rejects-valid: copy-initialization through user-defined conversion sequence fails
  2015-06-03  8:24 [Bug c++/66392] New: rejects-valid: copy-initialization through user-defined conversion sequence fails filip.roseen at gmail dot com
  2015-08-04 14:54 ` [Bug c++/66392] " paolo at gcc dot gnu.org
@ 2015-08-04 14:55 ` paolo.carlini at oracle dot com
  1 sibling, 0 replies; 3+ messages in thread
From: paolo.carlini at oracle dot com @ 2015-08-04 14:55 UTC (permalink / raw)
  To: gcc-bugs

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

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
                 CC|paolo.carlini at oracle dot com    |
         Resolution|---                         |FIXED
   Target Milestone|---                         |6.0

--- Comment #3 from Paolo Carlini <paolo.carlini at oracle dot com> ---
Done.


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

end of thread, other threads:[~2015-08-04 14:55 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-06-03  8:24 [Bug c++/66392] New: rejects-valid: copy-initialization through user-defined conversion sequence fails filip.roseen at gmail dot com
2015-08-04 14:54 ` [Bug c++/66392] " paolo at gcc dot gnu.org
2015-08-04 14:55 ` paolo.carlini at oracle 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).