Umesh Kalappa
2018-09-17 12:00:51 UTC
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 &= ~n1;
typecast the expression like "n& = (char)~n1" and warning goes away .
and when we investigated the gcc source and warning coming from
unsafe_conversion_p@ gcc/c-family/c-common.c:1226
if (TYPE_PRECISION (type) < TYPE_PRECISION (expr_type))
give_warning = UNSAFE_OTHER;
where TYPE_PRECISION (type) is 8 for char and TYPE_PRECISION
(expr_type) is 32 as expected for int .
is that expected behavior of gcc ?
clang compiles with no warnings .
Thank you
~Umesh
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 &= ~n1;
typecast the expression like "n& = (char)~n1" and warning goes away .
and when we investigated the gcc source and warning coming from
unsafe_conversion_p@ gcc/c-family/c-common.c:1226
if (TYPE_PRECISION (type) < TYPE_PRECISION (expr_type))
give_warning = UNSAFE_OTHER;
where TYPE_PRECISION (type) is 8 for char and TYPE_PRECISION
(expr_type) is 32 as expected for int .
is that expected behavior of gcc ?
clang compiles with no warnings .
Thank you
~Umesh