‘noreturn’ function does return

有些话、适合烂在心里 提交于 2019-12-01 16:12:13

It is possible to tell gcc that a particular function never returns. This permits certain optimizations and helps avoid spurious warnings of uninitialized variables.

This is done using the noreturn attribute:

void func() __attribute__ ((noreturn));

If the function does return despite the noreturn attribute, the compiler emits the warning you're seeing (which in your case gets converted into an error).

Since you're unlikely to be using noreturn in your code, the likely explanation is that you have a function whose name clashes with a standard noreturn function, as in the below example:

#include <stdlib.h>

void exit(int) {
}                // warning: 'noreturn' function does return [enabled by default]

Here, my exit clashes with exit(3).

Another obvious candidate for such a clash is abort(3).

Of course, if your function is actually called hello(), the culprit is almost certainly somewhere within your code base.

Most probably, the function is marked with __attribute__((noreturn)). However, it does in fact return (when control reaches the end of irs body, since it doesn't enter an infinite loop, it doesn't call other "noreturn" functions, etc.)

I don't see what your point is in 1. marking the function as non-returning, 2. writing a function that does nothing - probably you could just eliminate both?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!