Re: warning: conversion from ‘int’ to ‘char’ may change value

2018-09-20 Thread Jeff Law
elow case from trunk gcc we get the below >>>> warning (-Wconversion) i.e >>>> >>>> void start(void) { >>>>  char n = 1; >>>>  char n1 = 0x01; >>>>  n &=  ~n1; >>>> } >>>> >>>> $xgcc -S

Re: warning: conversion from ‘int’ to ‘char’ may change value

2018-09-20 Thread Martin Sebor
from trunk gcc we get the below warning (-Wconversion) i.e void start(void) { char n = 1; char n1 = 0x01; n &= ~n1; } $xgcc -S warn.c -nostdinc -Wconversion warning: conversion from ‘int’ to ‘char’ may change value [-Wconversion] n &= ~n1; [...] It looks like a bug to me. Decl

Re: warning: conversion from ‘int’ to ‘char’ may change value

2018-09-20 Thread Jason Merrill
>> >>>> When we try to compile the below case from trunk gcc we get the below >>>> warning (-Wconversion) i.e >>>> >>>> void start(void) { >>>> char n = 1; >>>> char n1 = 0x01; >>>> n &= ~n1;

Re: warning: conversion from ‘int’ to ‘char’ may change value

2018-09-20 Thread Eric Gallager
elow case from trunk gcc we get the below >>>> warning (-Wconversion) i.e >>>> >>>> void start(void) { >>>> char n = 1; >>>> char n1 = 0x01; >>>> n &= ~n1; >>>> } >>>> >>>> $xgcc -S warn

Re: warning: conversion from ‘int’ to ‘char’ may change value

2018-09-20 Thread Martin Sebor
= 0x01; n &= ~n1; } $xgcc -S warn.c -nostdinc -Wconversion warning: conversion from ‘int’ to ‘char’ may change value [-Wconversion] n &= ~n1; [...] It looks like a bug to me. Declaring n1 const avoids the warning at -O2 but in C but not at -O0. Perhaps at some optimization le

Re: warning: conversion from ‘int’ to ‘char’ may change value

2018-09-20 Thread Vincent Lefevre
On 2018-09-20 11:13:59 -0400, Jason Merrill wrote: > Indeed, whether this sort of warning is a false positive depends on > values, which the optimizers can always do better with. We could > build some logic into the front end, e.g. recognize that a & > expression will always fit in the smallest

Re: warning: conversion from ‘int’ to ‘char’ may change value

2018-09-20 Thread Vincent Lefevre
On 2018-09-20 22:57:00 +0800, Liu Hao wrote: > 在 2018/9/20 22:08, Vincent Lefevre 写道: > >> In C++, declaring n1 const avoids the warning regardless of > >> optimization levels. > > > > If the constant propagation is done at -O0, this could explain > > the behavior. > > > > Or do you mean that

Re: warning: conversion from ‘int’ to ‘char’ may change value

2018-09-20 Thread Jason Merrill
> char n = 1; >> char n1 = 0x01; >> n &= ~n1; >> } >> >> $xgcc -S warn.c -nostdinc -Wconversion >> warning: conversion from ‘int’ to ‘char’ may change value [-Wconversion] >> n &= ~n1; >> >> typecast the expression li

Re: warning: conversion from ‘int’ to ‘char’ may change value

2018-09-20 Thread Liu Hao
在 2018/9/20 22:08, Vincent Lefevre 写道: >> In C++, declaring n1 const avoids the warning regardless of >> optimization levels. > > If the constant propagation is done at -O0, this could explain > the behavior. > > Or do you mean that GCC remembers the type the data come from, > i.e. assuming char

Re: warning: conversion from ‘int’ to ‘char’ may change value

2018-09-20 Thread Vincent Lefevre
> char n = 1; > > char n1 = 0x01; > > n &= ~n1; > > } > > > > $xgcc -S warn.c -nostdinc -Wconversion > > warning: conversion from ‘int’ to ‘char’ may change value [-Wconversion] > > n &= ~n1; [...] > It looks like a bug to me. > > Dec

Re: warning: conversion from ‘int’ to ‘char’ may change value

2018-09-17 Thread Martin Sebor
On 09/17/2018 06:00 AM, Umesh Kalappa wrote: Hi All, When we try to compile the below case from trunk gcc we get the below warning (-Wconversion) i.e void start(void) { char n = 1; char n1 = 0x01; n &= ~n1; } $xgcc -S warn.c -nostdinc -Wconversion warning: conversion from ‘int’ to ‘

Re: warning: conversion from ‘int’ to ‘char’ may change value

2018-09-17 Thread David Brown
dinc -Wconversion > warning: conversion from ‘int’ to ‘char’ may change value [-Wconversion] > n &= ~n1; > > typecast the expression like "n& = (char)~n1" and warning goes away . > > and when we investigated the gcc source and warning coming from >

warning: conversion from ‘int’ to ‘char’ may change value

2018-09-17 Thread Umesh Kalappa
Hi All, When we try to compile the below case from trunk gcc we get the below warning (-Wconversion) i.e void start(void) { char n = 1; char n1 = 0x01; n &= ~n1; } $xgcc -S warn.c -nostdinc -Wconversion warning: conversion from ‘int’ to ‘char’ may change value [-Wconversion] n &am