Warnings building with clang
Submitted by Massimo
Link to original bug (#761170)
Description
I've just run
$make -sC app CC=clang &>out.log
$clang -v clang version 3.7.0 (tags/RELEASE_370/final) Target: x86_64-redhat-linux-gnu Thread model: posix Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-redhat-linux/5.3.1 Found candidate GCC installation: /usr/lib/gcc/x86_64-redhat-linux/5.3.1 Selected GCC installation: /usr/bin/../lib/gcc/x86_64-redhat-linux/5.3.1 Candidate multilib: .;@m64 Candidate multilib: 32;@m32 Selected multilib: .;@m64
and there are few kind of warnings that might be better to silence:
-Wsometimes-uninitialized example:
gimpimage-new.c:349:10: warning: variable 'has_alpha' is used uninitialized whenever switch case is taken [-Wsometimes-uninitialized] case 3: base_type = GIMP_RGB; ^ gimpimage-new.c:374:68: note: uninitialized use occurs here has_alpha), ^~~~~~~~~
-Wtautological-constant-out-of-range-compare comparisons of enum with -1 when -1 is not a valid enum value are apparently evaluated at compile-time, possibly making them useless, example:
gimpcomponenteditor.c:619:33: warning: comparison of constant -1 with expression of type 'GimpChannelType' is always true [-Wtautological-constant-out-of-rang editor->clicked_component != -1) ~~~~~~~~~~~~~~~~~~~~~~~~~ ^ ~~
-Wenum-conversion example:
gimpcursorview.c:492:38: warning: implicit conversion from enumeration type 'PangoStyle' to different enumeration type 'PangoAttrType' [-Wenum-conversion] PangoAttrType attribute = italic ? PANGO_STYLE_ITALIC : PANGO_STYLE_NORMAL; ~~~~~~~~~ ^~~~~~~~~~~~~~~~~~
That's easy to fix, just use a PangoStyle, it is a PangoStyle after all, perhaps naming it 'style'
-Wabsolute-value example:
gimpsheartool.c:185:11: warning: using integer absolute value function 'abs' when argument is of floating point type [-Wabsolute-value] if (abs (diffx) > 5 || abs (diffy) > 5) ^ gimpsheartool.c:185:11: note: use function 'fabs' instead if (abs (diffx) > 5 || abs (diffy) > 5) ^~~ fabs
obviously it is also possible to use the macro ABS
-Warray-bounds often refers to the inlined version of strcmp, but comparisons with the empty string (the warning message says index 1 is past the end of the array) could be changed to comparisons of the first char != (or ==) '\0'
example
gimpsearchpopup.c:523:1845: warning: array index 1 is past the end of the array (which contains 1 element) [-Warray-bounds] if (extension ({ size_t __s1_len, __s2_len; (__builtin_constant_p (entry_text) && __builtin_constant_p ("") && (__s1_len = strlen (entry_text), __s2_len
if (strcmp (entry_text, "") != 0) if (entry_text[0] != '\0')
-Wunused-const-variable example:
gimpmotionbuffer.c:85:25: warning: unused variable 'default_coords' [-Wunused-const-variable] static const GimpCoords default_coords = { 0.0, 0.0, 1.0, 0.0, 0.0, 0.5, 0.0, 0.0, 1.0, 1.0 }; lebl-dialog.c:16:21: warning: unused variable 'goatpb2' [-Wunused-const-variable] static const guint8 goatpb2[]; ^ lebl-dialog.c:17:21: warning: unused variable 'goatpb' [-Wunused-const-variable] static const guint8 goatpb[]; ^ lebl-dialog.c:18:21: warning: unused variable 'wanda' [-Wunused-const-variable] static const guint8 wanda[];
-Wtautological-compare enums probably default to unsigned if they do not have any negative values example:
gradient-editor-commands.c:123:18: warning: comparison of unsigned enum expression >= 0 is always true [-Wtautological-compare] color_type >= 0 && ~~~~~~~~~~ ^ ~ gradient-editor-commands.c:277:18: warning: comparison of unsigned enum expression >= 0 is always true [-Wtautological-compare] color_type >= 0 && ~~~~~~~~~~ ^ ~
Version: git master