Re: [PATCH 2/3] combine-diff: suppress a clang warning

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



John Keeping <john@xxxxxxxxxxxxx> writes:

> When compiling combine-diff.c, clang 3.2 says:
>
>     combine-diff.c:1006:19: warning: adding 'int' to a string does not
> 	    append to the string [-Wstring-plus-int]
> 		prefix = COLONS + offset;
> 			 ~~~~~~~^~~~~~~~
>     combine-diff.c:1006:19: note: use array indexing to silence this warning
> 		prefix = COLONS + offset;
> 				^
> 			 &      [       ]
>
> Suppress this by making the suggested change.
>
> Signed-off-by: John Keeping <john@xxxxxxxxxxxxx>
> ---

This was not lost in the noise.

I thought that this wasn't a serious patch, but your attempt to
demonstrate to others why patches trying to squelch clang warnings
are not necessarily a good thing to do.

Who is that compiler trying to help with such a warning message?
After all, we are writing in C, and clang is supposed to be a C
compiler.  And adding integer to a pointer to (const) char is a
straight-forward way to look at the trailing part of a given string.

> -		prefix = COLONS + offset;
> +		prefix = &COLONS[offset];

In other words, both are perfectly valid C.  Why should we make it
less readable to avoid a stupid compiler warning?
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]