As of [r10267] (and probably for quite a while before that),
unsigned char c = 1 << 7;
results in a warning "overflow in implicit constant conversion" . However, the constant is 128, which is perfectly within the range of unsigned int. I noticed this issue due to a failure of the valdiag regression testing.
Philipp
Bugs: #2827
Bugs: #3094
Discussion: warning 158: overflow in implicit constant conversion
Discussion: warning 158: overflow in implicit constant conversion
Wiki: SDCC 4.3.0 Release
Wiki: SDCC 4.4.0 Release
Wiki: SDCC 4.5.0 Release
Wiki: SDCC 4.6.0 Release
Looks like the 1 << 7 at some point is considered to be a signed char literal.
Philipp
The same problem happens for types other than char:
All give the same warning.
Philipp
However, for unsigned char, the false warning is always given, both on initialization and assignment. For the other unsigned types the false warning is only given on initialization.
Philipp
This, or a similar issue also affects operations other than <<:
https://www.mikrocontroller.net/topic/474289
I trying to resolve the similar [#2877] just before the last release, but couldn't find a correction simple enough that I had confidence that I wasn't inadvertently breaking something else. Because of the assignment to unsigned char, decorateType() is propagating RESULT_TYPE_CHAR which ends up causing the literal to convert from int to signed char.
Related
Bugs: #2877
As of r12014, I think this still happens.
I attach an example where 2 very similar expressions raise the warning or not, in case that helps.
Simply compiled using:
sdcc main.cMany thanks!