[cfe-dev] Is -Wno-return-type a warning or error?

David Blaikie via cfe-dev cfe-dev at lists.llvm.org
Thu Oct 29 08:10:27 PDT 2015


Intentional, I believe. We do have some warning which default to being
errors. I'm not sure of the specifics of the c language standard in this
case, but perhaps there's some case where this is not UB (if the return is
never executed, perhaps) so it may not technically be invalid c.
On Oct 29, 2015 4:55 AM, "Dan Liew via cfe-dev" <cfe-dev at lists.llvm.org>
wrote:

> Hi,
>
> I was playing with Clang 3.7 on some old code I noticed that
> ``-Wreturn-type`` seems to be treated as error.
>
> For example
>
> ```
> int foo() {
>     int x = 5;
>     return;
> }
>
> int main() {
>     int x = foo();
>     return 0;
> }
> ```
>
> Now try building
> ```
> $ clang -std=c99 noret.c
> noret.c:3:5: error: non-void function 'foo' should return a value
> [-Wreturn-type]
>     return;
>     ^
> 1 error generated.
> ```
>
> It's good that Clang flags up bad code like this but what is confusing
> me is the Clang driver is
>
> * Treating this as an error even though I haven't passed ``-Werror``.
> * I can suppress this with ``-Wno-return-type``.
>
> So I'm not really sure if this is a "warning" or an "error". I expect
>
> * If it's an "error" then I shouldn't be able to suppress it with the
> ``-Wno-return-type`` flag.
> * If it's a "warning" and I haven't passed ``-Werror`` then Clang
> should note the warning but not treat it as an error.
>
> Is Clang's current (and reasonable) behaviour intentional or this a bug?
>
> Thanks,
> Dan.
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20151029/5b140631/attachment.html>


More information about the cfe-dev mailing list