[cfe-dev] Getting better diagnostics from clang in portable code

Marshall Clow mclow.lists at gmail.com
Tue Oct 25 09:39:46 PDT 2011


This is not a proposal, but rather a starting point for a discussion.

I've been running a fair amount of ostensibly portable code through clang, and I'm getting a bunch of warnings that, while correct, are (I believe) unhelpful.

Here are two examples:

1) libjpeg tests for integer size mismatch/overflows with:
> 		if ((long) jd_samplesperrow != samplesperrow)
and clang helpfully responds with (when compiling on x86_64):
	jdmaster.c:285:31: warning: Both operands to '!=' always have the same value

2) crypto++ has a template that looks like this:

> template <class T>
> std::string IntToString(T a, unsigned int base = 10)
> {
> 	if (a == 0)
> 		return "0";
> 	bool negate = false;
> 	if (a < 0)
> 	{
> 		negate = true;
… and so on.

and when instantiated like this
		IntToString<unsigned long>

clang pipes up with:
./misc.h:414:8: warning: comparison of unsigned expression < 0 is always false [-Wtautological-compare]
        if (a < 0)

I can find other examples if people want to see them.
Both of these warnings are correct (in the current environment), and yet, I don't think they're that helpful (in these cases).
(For the crypto++ case, I edited the makefile to add -Wno-tautological-compare)

Anyone have any ideas about what can be done to recognize these kinds of cases and not warn on them (as opposed to other 
places where the warnings are more useful)?

Thanks in advance!

-- Marshall





More information about the cfe-dev mailing list