c++ - How to detect no-return statement from a function -


i have function returns non-void. on caller side, want detect whether return statement called in original function or not.

i know, not allowed have non-void function return nothing , throw warning in gcc. want print runtime error based on whether return called or control reached end of function.

the callee defined user. provide declaration. so, want ensure implementer of callee function, doesn't skip "return" statement.

you can't determine how function returns caller (other whether throws exception or returns). thing can prevent function returning explicitly using compiler warning or put run-time error call @ end of function don't want have control fall off end of. 1 trick might able have return type function have default constructor gives run-time error; return statements need use other constructor. once that, though, might add error call end of function or change return type gcc warning.


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -