public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/47080] New: explicit conversion function return conversions not restricted to qualifications
@ 2010-12-28 18:20 schaub.johannes at googlemail dot com
  2010-12-28 19:10 ` [Bug c++/47080] " schaub.johannes at googlemail dot com
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: schaub.johannes at googlemail dot com @ 2010-12-28 18:20 UTC (permalink / raw)
  To: gcc-bugs

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

           Summary: explicit conversion function return conversions not
                    restricted to qualifications
           Product: gcc
           Version: 4.6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: schaub.johannes@googlemail.com


n3225 only allows a qualification conversion for the return of an explicit
conversion function when converting to a non-class type:

struct A {
  explicit operator int();
};

int main() {
  bool b((A())); // should not work
  !A(); // should not work!
}

Both are not valid according to 13.3.1.5/1 (second case uses candidate function
provided by 13.6/23, for which the bool parameter uses contextual conversion).
GCC accepts both.


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

* [Bug c++/47080] explicit conversion function return conversions not restricted to qualifications
  2010-12-28 18:20 [Bug c++/47080] New: explicit conversion function return conversions not restricted to qualifications schaub.johannes at googlemail dot com
@ 2010-12-28 19:10 ` schaub.johannes at googlemail dot com
  2011-06-20  4:11 ` [Bug c++/47080] [C++0x] " jason at gcc dot gnu.org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: schaub.johannes at googlemail dot com @ 2010-12-28 19:10 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Johannes Schaub <schaub.johannes at googlemail dot com> 2010-12-28 19:10:25 UTC ---
It should be noted that this can yield to ambiguities in combination with other
conversion functions. Consider

enum E { };
struct A {
  explicit operator int();
  operator E();
};

bool operator!(E);

int main() {
  !A(); // should work, but GCC rejects!
}

In this case, since GCC considers both "operator int" and "operator E" for the
contextual conversion to bool, but neither is better than the other, it assigns
the ambiguous conversion sequence for the builtin operator. For conversion to
the E-taking one, it unambiguously uses "operator E". Since the ambiguous
conversion sequence cannot be compared to any other conversion sequence, we
have an ambiguity between the builtin operator and our own defined one. 

On a n3225-conforming implementation, both operator functions would use
"operator E", and then it would be found that "operator!(E)" matches the return
of the conversion function better than the built-in candidate, and would thus
be selected.

So it's really a "rejects-valid", as is basically any C++ issue of this sort
anyway, since they can all be "exploited" by using SFINAE.


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

* [Bug c++/47080] [C++0x] explicit conversion function return conversions not restricted to qualifications
  2010-12-28 18:20 [Bug c++/47080] New: explicit conversion function return conversions not restricted to qualifications schaub.johannes at googlemail dot com
  2010-12-28 19:10 ` [Bug c++/47080] " schaub.johannes at googlemail dot com
@ 2011-06-20  4:11 ` jason at gcc dot gnu.org
  2011-06-20 14:43 ` jason at gcc dot gnu.org
  2011-06-20 14:45 ` jason at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: jason at gcc dot gnu.org @ 2011-06-20  4:11 UTC (permalink / raw)
  To: gcc-bugs

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

Jason Merrill <jason at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |ASSIGNED
   Last reconfirmed|                            |2011.06.20 04:10:18
                 CC|                            |jason at gcc dot gnu.org
         AssignedTo|unassigned at gcc dot       |jason at gcc dot gnu.org
                   |gnu.org                     |
     Ever Confirmed|0                           |1


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

* [Bug c++/47080] [C++0x] explicit conversion function return conversions not restricted to qualifications
  2010-12-28 18:20 [Bug c++/47080] New: explicit conversion function return conversions not restricted to qualifications schaub.johannes at googlemail dot com
  2010-12-28 19:10 ` [Bug c++/47080] " schaub.johannes at googlemail dot com
  2011-06-20  4:11 ` [Bug c++/47080] [C++0x] " jason at gcc dot gnu.org
@ 2011-06-20 14:43 ` jason at gcc dot gnu.org
  2011-06-20 14:45 ` jason at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: jason at gcc dot gnu.org @ 2011-06-20 14:43 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Jason Merrill <jason at gcc dot gnu.org> 2011-06-20 14:40:43 UTC ---
Author: jason
Date: Mon Jun 20 14:40:38 2011
New Revision: 175217

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=175217
Log:
    PR c++/47080
    * call.c (rejection_reason_code): Add rr_explicit_conversion.
    (print_z_candidate): Handle it.
    (explicit_conversion_rejection): New.
    (build_user_type_conversion_1): Reject an explicit conversion
    function that requires more than a qualification conversion.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/explicit6.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/call.c
    trunk/gcc/testsuite/ChangeLog


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

* [Bug c++/47080] [C++0x] explicit conversion function return conversions not restricted to qualifications
  2010-12-28 18:20 [Bug c++/47080] New: explicit conversion function return conversions not restricted to qualifications schaub.johannes at googlemail dot com
                   ` (2 preceding siblings ...)
  2011-06-20 14:43 ` jason at gcc dot gnu.org
@ 2011-06-20 14:45 ` jason at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: jason at gcc dot gnu.org @ 2011-06-20 14:45 UTC (permalink / raw)
  To: gcc-bugs

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

Jason Merrill <jason at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED
   Target Milestone|---                         |4.7.0

--- Comment #3 from Jason Merrill <jason at gcc dot gnu.org> 2011-06-20 14:44:15 UTC ---
Fixed for 4.7.0.


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

end of thread, other threads:[~2011-06-20 14:45 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-12-28 18:20 [Bug c++/47080] New: explicit conversion function return conversions not restricted to qualifications schaub.johannes at googlemail dot com
2010-12-28 19:10 ` [Bug c++/47080] " schaub.johannes at googlemail dot com
2011-06-20  4:11 ` [Bug c++/47080] [C++0x] " jason at gcc dot gnu.org
2011-06-20 14:43 ` jason at gcc dot gnu.org
2011-06-20 14:45 ` jason 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).