Skip to Main Content

DevOps, CI/CD and Automation

Inconsistent handling of operator delete

kovalAug 21 2017 — edited Aug 21 2017

Studio 12.5 and 12.6 incorrectly handles operator delete(void*, size_t) in constructor initializer list.

The following code sample shows the problem.

#include <new>

class C {

    friend class D;

    friend class E;

    void* operator new(std::size_t);

    void operator delete(void*);

    void operator delete(void*, std::size_t) = delete;

};

class D {

    C* c;

    D(): c(new C) { }

};

class E {

    C* c = new C;

};

Error:

line 15: Error: Using deleted function 'static C::operator delete(void*, unsigned)'.

1 Error(s) detected.

As you can see, no error is reported in class E where C::operator new is called in direct initializer. In class D same expression is not accepted in constructor initializer list.

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 18 2017
Added on Aug 21 2017
1 comment
161 views