[LLVMbugs] [Bug 11274] New: Missing warning for -Wconversion with compound assignment

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Mon Oct 31 01:54:41 PDT 2011


http://llvm.org/bugs/show_bug.cgi?id=11274

             Bug #: 11274
           Summary: Missing warning for -Wconversion with compound
                    assignment
           Product: clang
           Version: trunk
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Frontend
        AssignedTo: unassignedclangbugs at nondot.org
        ReportedBy: pat.pannuto+llvm at gmail.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified


A warning is not generated for the compound assignment case, though it is for
standard operation + assignment.

Simple test case:

int main() {
    uint8_t a = 1;
    a <<= 1;     // missing warning

    uint8_t b = 1;
    b = b << 1;  // warns correctly
}

Generates a warning only for b, but not for a:

conv.c:9:6: warning: implicit conversion loses integer precision: 'int' to
'uint8_t'
      (aka 'unsigned char') [-Wconversion]
        b = b << 1;
          ~ ^~~~~~

gcc v4.5 gets this right:

conv.c:6:2: warning: conversion to ‘uint8_t’ from ‘int’ may alter its value
conv.c:9:2: warning: conversion to ‘uint8_t’ from ‘int’ may alter its value


By my reading of 6.5.16.2 Compound assignment, the two should be consistent.
  For the other operators, each operand shall have arithmetic type consistent
with those
allowed by the corresponding binary operator.


--

First bug report of any kind to llvm, I believe I've followed preferred style /
info, please let me know if otherwise.

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list