[Bug c/70389] New: uint_16t left shift with -Wconversion produces incorrect warning

2016-03-24 Thread bobgmeyers at muchomail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70389

Bug ID: 70389
   Summary: uint_16t left shift with -Wconversion produces
incorrect warning
   Product: gcc
   Version: 4.8.2
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c
  Assignee: unassigned at gcc dot gnu.org
  Reporter: bobgmeyers at muchomail dot com
  Target Milestone: ---

This code:

int
main(void){
  uint16_t x;

  x=5;
  do{
x<<=1U;
x++;
  }while(1);
}

The code obviously outputs nothing, but this is just an example of this bug
which happens in every case as described below.

with -Wconversion it produces:

warning: conversion to ‘uint16_t’ from ‘int’ may alter its value [-Wconversion]
 x<<=1U;

How on earth could x<<1U end up being an int? x isn't signed and 1U isn't
signed (and according to the spec, the type of 1U is not relevant to the type
of x<<1U). I tried uint32_t and the error went away, so it looks like a problem
with uint16_t. Right shift is also OK.

Might relate to:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=59840
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=34389

[Bug c/70389] uint_16t left shift with -Wconversion produces incorrect warning

2016-03-25 Thread bobgmeyers at muchomail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70389

--- Comment #2 from Bob Meyers  ---
Does the most recent C spec actually say that short unsigned ints should be
promoted to signed ints prior to a left shift? (But somehow "x++" just
increments the short unsigned int x with no such implicit conversion, and so
does not trigger the same -Wconversion error.) That seems inconsistent, but if
it's true, then this is correct behavior. Thanks for the comment.