cpp: ensure we have a return type before dereferencing it