Bug 6044

Summary: -Wconversion is not enabled by default
Product: uClibc Reporter: Jeffrey Walton <noloader>
Component: OtherAssignee: unassigned
Status: NEW ---    
Severity: minor CC: uclibc-cvs
Priority: P5    
Version: 0.9.33.3   
Target Milestone: ---   
Hardware: PC   
OS: Linux   
Host: Target:
Build:

Description Jeffrey Walton 2013-03-02 23:20:41 UTC
-Wconversion is not enabled by default. Closely related is -Wsign-conversion (included in -Wconversion), which is also not present. -Wconversion is enabled by "Enable extra annoying warnings" (EXTRA_WARNINGS).

-Wconversion and -Wsign-conversion are important because -1 > 1 after C/C++ promotion rules. The following will likely produce unexpected results:

  int x = GetX(); // assume -1
  unsinged int y = GetY(); // assume 1

  if(x > y)
    printf("%d is greater than %u", x, y);
  else
    printf("%d is not greater than %u", x, y);

Apparently, one of the uClibc developer was bitten by this or a similar langauge feature. From Rules.mak:

# Why -funsigned-char: I hunted a bug related to incorrect
# sign extension of 'char' type for 10 hours straight. Not fun.
CPU_CFLAGS-y := -funsigned-char -fno-builtin

-Wconversion can produce a lot of output, but the output is usually correct. Its painful to turn the warning on for a mature product because a lot of slop has crept into the project. It only "annoying" because the programmers have not been mindful of details :)