llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

clang misses useful diagnostic for private `operator delete` in template base class

Open Rush10233 opened this issue 2 years ago • 0 comments

Consider the following code:

template <typename T>struct QCachedT{  
    void operator delete(void *, T *) {}
};

struct thing_t :private QCachedT<int>{

};  

int main() {     
    auto thing=new thing_t;    
    //error
    //delete thing_t;
}

Clang will not report any error for the private delete operator until it is explicitly called. That seems inappropriate because clang will error immediately after using the new operator if the base class QCachedT is non-template instead. As a comparison, GCC always provides an error right after the new statement is created no matter whether QCachedT is a template class or not.

https://godbolt.org/z/r71e3WT5h

Rush10233 avatar Jul 15 '24 11:07 Rush10233