The Standard requires GCC to not accept this snippet. Its description of
"delete" does not dictate overload resolution, but requires a single conversion
function to pointer type. This was handled correctly by GCC4.4, but fails with
4.6 and 4.5 (regression?)

struct A {
  operator int*() { return 0; }
  operator int*() const { return 0; }
};

int main() {
  A a;
  int *p = a; // works
  delete a; // shouldn't work, but does!
}

Expected output:

main1.cpp:9:3: error: ambiguous conversion of delete expression of type 'A' to
a pointer
  delete a; // shouldn't work, but does!
  ^      ~
main1.cpp:2:3: note: candidate function                                         
  operator int*() { return 0; }
  ^
main1.cpp:3:3: note: candidate function                                         
  operator int*() const { return 0; }
  ^
1 error generated.


-- 
           Summary: "delete" does overload resolution for class operands,
                    but shouldn't.
           Product: gcc
           Version: 4.5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: schaub-johannes at web dot de
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu


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

Reply via email to