[Bug c++/107495] New: GCC does not consider the right contextual implicit conversions

dangelog at gmail dot com gcc-bugzilla@gcc.gnu.org
Tue Nov 1 14:23:33 GMT 2022


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

            Bug ID: 107495
           Summary: GCC does not consider the right contextual implicit
                    conversions
           Product: gcc
           Version: 12.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: dangelog at gmail dot com
  Target Milestone: ---

Testcase:

    struct Test {
        operator int *() const;
        operator void *() const;
    };

    int main() {
        Test t;
        delete t;
    }


GCC rejects this:

<source>: In function 'int main()':
<source>:32:12: error: ambiguous default type conversion from 'Test'
   32 |     delete t;
      |            ^
<source>:32:12: note:   candidate conversions include 'Test::operator void*()
const' and 'Test::operator int*() const'
<source>:32:12: error: type 'struct Test' argument given to 'delete', expected
pointer



But this is wrong. https://eel.is/c++draft/expr.delete#1.sentence-5 says "If of
class type, the operand is contextually implicitly converted to a pointer to
object type" and the attached note explicitly says "This implies that an object
cannot be deleted using a pointer of type void* because void is not an object
type".

The definition of contextual conversion says
https://eel.is/c++draft/conv#general-5 :

"C is searched for non-explicit conversion functions whose return type is cv T
or reference to cv T such that T is allowed by the context. There shall be
exactly one such T."


There is exactly one such T (conversion to pointer of object type), so GCC is
rejecting valid code.


More information about the Gcc-bugs mailing list