On 27/02/14 07:50, Mingjie Xing wrote: > Hello, > > I'm wondering if it's a good idea to turn on some warnings by default > (or even promote them to error), such as -Wreturn-type on C. This > would help programmers to avoid some mistakes. > > Regards, > Mingjie >
Personally, I think gcc should issue a warning if it is run without at least "-Wall" (or "-Wno-all"), telling the user that they have forgotten to enable warnings. /That/ would help people avoid mistakes. It should also warn if there is no optimisation level, to stop people accidentally generating big and slow code. It's not going to happen, of course - compatibility with existing Makefiles, the users' right to make mistakes if they want, etc. But it might be reasonable to have warnings when the compiler can see without doubt that there is undefined behaviour going on, such as a missing return. The trouble is, it is only reasonable to have it by default if there is /no/ doubt that it will be run - the compiler can't really insist on issuing warnings on code that is compiled but not used. And since it often can't tell what will be used, it won't often be able to issue such warnings - and gcc would then have to figure out what code is definitely reachable from main() and apply "-Wreturn-type", etc., to that code, while leaving the warnings off for other code. David