Our website uses cookies to enhance your browsing experience.
Accept
to the top
>
>
>
Examples of errors detected by the...

Examples of errors detected by the V1062 diagnostic

V1062. Class defines a custom new or delete operator. The opposite operator must also be defined.


DeepSpeech

V1062 The 'DfsState' class defines a custom 'new' operator. The 'delete' operator must also be defined. dfs-visit.h 62

 void* MemoryPool<DfsState<FST>>::Allocate() { if (free_list_ == nullptr) { auto *link = static_cast<Link *>(mem_arena_.Allocate(1)); link->next = nullptr; return link; } else { auto *link = free_list_; free_list_ = link->next; return link; } } void MemoryPool<DfsState<FST>>::Free(void *ptr) { if (ptr) { auto *link = static_cast<Link *>(ptr); link->next = free_list_; free_list_ = link; } } // An FST state's DFS stack state. template <class FST> struct DfsState { public: .... void *operator new(size_t size, MemoryPool<DfsState<FST>> *pool) { return pool->Allocate(); } .... } 

A programmer defined the custom 'new' operator, which adds an element to the linked list using the 'Allocate()' function, but forgot to add a custom 'delete', which should use the 'Free()' function.

Similar errors can be found in some other places:

  • V1062 The 'VectorState' class defines a custom 'new' operator. The 'delete' operator must also be defined. vector-fst.h 31
  • V1062 The 'CacheState' class defines a custom 'new' operator. The 'delete' operator must also be defined. cache.h 65