[cfe-commits] [PATCH][driver] Frontend parsing of warnings and compliance with gcc

Chad Rosier mcrosier at apple.com
Tue Jan 31 14:49:53 PST 2012


The clang frontend currently parses warning options in the canonical "last option wins" paradigm.  This leads to what odd behavior IMO and non-compliance to how gcc handles things.

For example,

mcrosier$ cat t.c
int main() { return implicit(); }

mcrosier$ clang -Werror=implicit -Wall -c t.c -o /dev/null
t.c:1:21: warning: implicit declaration of function 'implicit' is invalid in C99 [-Wimplicit-function-declaration]
int main() { return implicit(); }
                    ^
1 warning generated.

Reversing the order of the warning options results in an error:
mcrosier$ clang -Wall -Werror=implicit -c t.c -o /dev/null
t.c:1:21: error: implicit declaration of function 'implicit' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
int main() { return implicit(); }
                    ^
1 error generated.

AFAIK gcc always emits an error.

If I understand the gcc standard correctly (and admittedly I'm no expert), I believe a -W option should never downgrade something that has already been marked as an error/fatal warning.

The attached patch does precisely this.  The other practical effect is that if you would like to change a warning that is an error by default to just a warning you need to use the -Wno-error=foo option rather then -Wfoo.

 Chad

-------------- next part --------------
A non-text attachment was scrubbed...
Name: fe_warnings.diff
Type: application/octet-stream
Size: 4564 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20120131/249ec174/attachment.obj>


More information about the cfe-commits mailing list