Why doesn't compile issue an error for code that results in undefined behavior
For example, articles usually say that if malloc and delete is paired up, or say that it is wrong and don't do it. 

But why doesn't compiler do some checking for us. 

Will there be any cases that this kind of code is right and intended？ Therefor compiler can't always say it's wrong to do it?

Or is there any technically difficulties for compiler to do that?
Why doesn't compile issue an error for code that results in undefined behavior
===

For example, articles usually say that if malloc and delete is paired up, or say that it is wrong and don't do it. 

But why doesn't compiler do some checking for us. 

Will there be any cases that this kind of code is right and intended？ Therefor compiler can't always say it's wrong to do it?

Or is there any technically difficulties for compiler to do that?