[PATCH] NoReturn Warning: Non-Void Return Type

dblaikie at gmail.com dblaikie at gmail.com
Sun Jan 5 17:30:18 PST 2014

On Sun Jan 05 2014 at 5:18:13 PM, Michael Bao <mike.h.bao at gmail.com> wrote:

> On Sun, Jan 5, 2014 at 7:30 PM, David Blaikie <dblaikie at gmail.com> wrote:
> >
> >   Is this an existing warning in another compiler?
> The only other compiler I have access to right now is GCC 4.8 and from
> what I can tell they do not have this warning. However, their docs say
> that it does not make sense for a noreturn function to have a return
> type other than void
> (http://gcc.gnu.org/onlinedocs/gcc-4.8.0/gcc/Function-Attributes.html).

> >   Is it finding bugs?
> I can't say for sure if this particular would find bugs or not, but I
> think marking a noreturn function as having a return type could
> potentially be confusing?.

That may not meet the bar for Clang warnings. We tend to only add warnings
that have a very high bug-finding, very low false-positive (where
false-positive is defined as "flags a case that is not a bug").

> >   How does this interact with virtual functions? (what if I'm overriding
> a
> >   non-void non-noreturn function with a noreturn function?)
> If I understand your question correctly...I quickly made up this example:
> class TestClass {
>   virtual int cfoo() {
>     return 0;
>    }
> };
> class TestClass2: public TestClass {
>   __attribute__((noreturn)) virtual int cfoo() {
>     while(1){}
>     return 1;
>    }
> };
> The warning is emitted on the cfoo() function in TestClass2 as expected.

"as expected" may be a problem. What should the user do in this case? Is
there any way to suppress the warning here if this is the API the user

> Thanks!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140106/f56c41fd/attachment.html>

More information about the cfe-commits mailing list