<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 14 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
p
        {mso-style-priority:99;
        mso-margin-top-alt:auto;
        margin-right:0in;
        mso-margin-bottom-alt:auto;
        margin-left:0in;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
span.EmailStyle18
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri","sans-serif";}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">C99 6.8.6.4 p1 says:  A return statement without an expression shall only appear in a function whose return type is void.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">So, the bare "return;" in foo() is really an error.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">Falling off the end of a non-void function (without an actual "return;" statement) is UB only if the return value is used by the caller.<o:p></o:p></span></p>
<p class="MsoNormal"><a name="_MailEndCompose"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">That is, if you removed the "return;" from foo() and then didn't use its return value in the call from main(), it would be legal. 
 Although, I'd guess you'd see the same diagnostic as a warning, not an error.<o:p></o:p></span></a></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">--paulr<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<div style="border:none;border-left:solid blue 1.5pt;padding:0in 0in 0in 4.0pt">
<div>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">From:</span></b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif""> cfe-dev [mailto:cfe-dev-bounces@lists.llvm.org]
<b>On Behalf Of </b>David Blaikie via cfe-dev<br>
<b>Sent:</b> Thursday, October 29, 2015 8:10 AM<br>
<b>To:</b> Dan Liew<br>
<b>Cc:</b> Clang Dev<br>
<b>Subject:</b> Re: [cfe-dev] Is -Wno-return-type a warning or error?<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<p>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.<o:p></o:p></p>
<div>
<p class="MsoNormal">On Oct 29, 2015 4:55 AM, "Dan Liew via cfe-dev" <<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a>> wrote:<o:p></o:p></p>
<p class="MsoNormal">Hi,<br>
<br>
I was playing with Clang 3.7 on some old code I noticed that<br>
``-Wreturn-type`` seems to be treated as error.<br>
<br>
For example<br>
<br>
```<br>
int foo() {<br>
    int x = 5;<br>
    return;<br>
}<br>
<br>
int main() {<br>
    int x = foo();<br>
    return 0;<br>
}<br>
```<br>
<br>
Now try building<br>
```<br>
$ clang -std=c99 noret.c<br>
noret.c:3:5: error: non-void function 'foo' should return a value<br>
[-Wreturn-type]<br>
    return;<br>
    ^<br>
1 error generated.<br>
```<br>
<br>
It's good that Clang flags up bad code like this but what is confusing<br>
me is the Clang driver is<br>
<br>
* Treating this as an error even though I haven't passed ``-Werror``.<br>
* I can suppress this with ``-Wno-return-type``.<br>
<br>
So I'm not really sure if this is a "warning" or an "error". I expect<br>
<br>
* If it's an "error" then I shouldn't be able to suppress it with the<br>
``-Wno-return-type`` flag.<br>
* If it's a "warning" and I haven't passed ``-Werror`` then Clang<br>
should note the warning but not treat it as an error.<br>
<br>
Is Clang's current (and reasonable) behaviour intentional or this a bug?<br>
<br>
Thanks,<br>
Dan.<br>
_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><o:p></o:p></p>
</div>
</div>
</div>
</body>
</html>