You sound like you want it to fail... maybe if you could explain your logic in wanting this this to happen, if this really is what you want.
Is your expectation that a core OpenGL 4.2 profile should fail when legacy code is used?
I suspect that the most reliable way to unsure this happens is to prevent the code from compiling to begin with. You would likely have problems doing this if you are using an extension wrangler. It's kind of hard to pull apart everything they attach to your program.
If, however, you decide to only use gl.h and a glext.h header files for initializing OpenGL, then you have pretty much full control with easy access to functions you want to omit.
Search online for "OpenGL deprecated" then search for those functions and definitions in the above mentioned header files. Manually delete everything that you do not want to support. Add only what you do want to use. What you can't remove you will know not to use.
Or you could hope that someone will do this for you seamlessly in the background. Personally, I'd rather take control of this than leave it in the hands of others.