Why there is no compiler error when return statement is not present?
问题 Unlike Java, in C/C++ following is allowed : int* foo () { if(x) return p; // what if control reaches here } This often causes crashes and hard to debug problems. Why standard doesn't enforce to have final return for non- void functions ? (Compilers generate error for wrong return value) Is there any flag in gcc/msvc to enforce this ? (something like -Wunused-result ) 回答1: It is not allowed (undefined behaviour). However, the standard does not require a diagnostic in this case. The standard