[Bug c++/40752] -Wconversion generates false warnings for operands not larger than target type

chengniansun at gmail dot com gcc-bugzilla@gcc.gnu.org
Mon Feb 10 01:14:00 GMT 2014


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40752

--- Comment #25 from Chengnian Sun <chengniansun at gmail dot com> ---
Today I encountered a similar case as follows. The conversion warning by gcc is
not true as right-shifting an unsigned short decreases the value. 

BTW clang does not emit warnings for this code snippet. 


$: cat s1.c
unsigned short fn(unsigned short a, int right) {
  return a >> right;
}
$: gcc-trunk -c -Wconversion s1.c
s1.c: In function ‘fn’:
s1.c:2:3: warning: conversion to ‘short unsigned int’ from ‘int’ may alter its
value [-Wconversion]
   return a >> right;
   ^
$: clang-trunk -c -Wconversion s1.c
$:


More information about the Gcc-bugs mailing list