[Patch] Warning for mismatched header guard.

Richard Trieu rtrieu at google.com
Mon Apr 29 16:38:06 PDT 2013


The attached patch adds a new warning that triggers on mismatched header
guards.  Typically, a header guard would look like:

#ifndef HEADER_NAME_
#define HEADER_NAME_

int foo = 42;

#endif

Occasionally, typos will cause the header guard to not function properly
but still compile, such as:

#ifndef HEADER_NAME_
#define HEDAER_NAME_

int foo = 42;

#endif

The two problem are:
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.
2) When the header is included twice, the error is "redefinition of 'foo'"
which obscures the actual source of the problem.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130429/440c9668/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: header-guard1.patch
Type: application/octet-stream
Size: 12614 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130429/440c9668/attachment.obj>


More information about the cfe-commits mailing list