<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On Sep 4, 2011, at 2:48 PM, David Blaikie wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div class="gmail_quote"><div>Here's a patch to add FixIt diagnostics to the "main cannot/should not be static" and "main cannot be inline" warnings/errors.</div><div><br></div><div>Some context from a previous email conversation with Douglas Gregor:</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div style="word-wrap:break-word"><div><div class="im"><div>No, main cannot be a template.</div></div></div>
</div></blockquote><div><br></div><div>Seems the error for templated main was coming from the ActOnFunctionDeclarator use case anyway - by the time we got to template instantiation we'd already diagnosed this problem so it was just redundant to check there.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div style="word-wrap:break-word"><div><div class="im"><br><blockquote type="cite"><div class="gmail_quote">
<div><font face="Verdana, Geneva, Arial, Helvetica, sans-serif"><span style="font-size:14px">So should we just push the isMain/checkMain checking up into ActOnFunctionDeclarator instead? Then it wouldn't add any overhead to irrelevant contexts (methods & templates) & the checking could be more descriptive.</span></font></div>
</div></blockquote><br></div></div><div>Works for me!</div></div></blockquote><div><br></div><div>So I've done that - pulling out the first few checks from CheckFunctionDeclaration into the two call sites in ActOnFunctionDeclarator & then passing the DeclSpec to the CheckMain calls. I could refactor that common "IsMain/CheckMain/CheckFunctionDeclarator" into one function to use from these two (non-C++ and C++) call sites in ActOnFunctionDeclarator if you think that'd be better.<br>
<br>I also split up the static/inline warnings so they could warn against the keyword rather than against the 'main' (when warning against the 'main' and issuing a fixit for 'static' on a different line (or inside a macro), the diagnostic just printed out without the fixit) - this seemed consistent with other cases relating to spurious static in SemaDecl.cpp (some other cases include the fixit, some don't - I'll see about making some patches for those other missing fixits too).<br></div></div></blockquote><div><br></div><div>+ Diag(DS.getStorageClassSpecLoc(), getLangOptions().CPlusPlus ? diag::err_static_main : diag::warn_static_main) << FixItHint::CreateRemoval(DS.getStorageClassSpecLoc());</div><div>+ if (FD->isInlineSpecified())</div><div>+ Diag(DS.getInlineSpecLoc(), diag::err_inline_main) << FixItHint::CreateRemoval(DS.getInlineSpecLoc());</div><div><br></div><div>Please limit code to 80 columns. Otherwise, looks good! If you don't have commit access already, please follow the directions at</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> <a href="http://llvm.org/docs/DeveloperPolicy.html#commitaccess">http://llvm.org/docs/DeveloperPolicy.html#commitaccess</a></span></div><div><br></div><div>so you can commit this yourself.</div><div><br></div></div><div><br><blockquote type="cite"><div class="gmail_quote"><div>After this I'll just keep working my way down through CheckMain to add fixits to each of the suggestions where they're applicable.</div></div></blockquote><br></div><div>Okay!</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>- Doug</div><br></body></html>