<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Apr 30, 2013 at 1:38 AM, Richard Trieu <span dir="ltr"><<a href="mailto:rtrieu@google.com" target="_blank">rtrieu@google.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">The attached patch adds a new warning that triggers on mismatched header guards.  Typically, a header guard would look like:<div>
<br></div><div>#ifndef HEADER_NAME_</div><div>#define HEADER_NAME_</div>
<div><br></div><div>int foo = 42;<br></div><div><br></div><div>#endif</div><div><br></div><div>Occasionally, typos will cause the header guard to not function properly but still compile, such as:</div>
<div><br></div><div><div>#ifndef HEADER_NAME_</div><div>#define HEDAER_NAME_</div><div><br></div><div>int foo = 42;</div><div><br></div><div>#endif</div><div><br></div><div>The two problem are:</div>
<div>1) The header may be developed and used while only being included once with no problems.  Thus, it may take some time before the header guard functionality is required.</div><div>2) When the header is included twice, the error is "redefinition of 'foo'" which obscures the actual source of the problem.</div>

</div></div>
<br>_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
<br></blockquote></div><br></div><div class="gmail_extra">Hi Richard,<br><br></div><div class="gmail_extra">First of all, that certainly is a great idea!<br><br></div><div class="gmail_extra">On the same line, during development I have encountered a second "stupid" pattern:<br>
<br></div><div class="gmail_extra">// A.h<br></div><div class="gmail_extra">#ifndef A_H<br></div><div class="gmail_extra">#define A_H<br><br></div><div class="gmail_extra">#endif<br></div><div class="gmail_extra"><br></div>
<div class="gmail_extra">// B.h<br></div><div class="gmail_extra">#ifndef A_H<br></div><div class="gmail_extra">#define A_H<br><br></div><div class="gmail_extra">#endif<br><br></div><div class="gmail_extra">// C.pp<br>#include <B.h></div>
<div class="gmail_extra">#include <A.h><br><br></div><div class="gmail_extra">// some weird error about B not being defined, WHY ?<br><br></div><div class="gmail_extra">It's typically hard to track down, because with the game of bringing includes in, whilst A is clearly being shadowed "by something" (at least, clear to a seasoned developer), it's pretty hard to tell WHO is shadowing A.<br>
<br><br></div><div class="gmail_extra">So I wonder if in the same vein it would make sense to warn where two different files being included in the same translation unit are relying on the same header guards.<br><br></div>
<div class="gmail_extra">I have no idea about that false-ratio this could bring in though :/<br><br></div><div class="gmail_extra">-- Matthieu<br></div></div>