http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59840
Bug ID: 59840
Summary: -Wconversion produces incorrect warning when value is
shifted by 0
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: rafal at rawicki dot org
Consider following code:
$ cat foo.cpp
#include <stdint.h>
uint16_t foo(uint8_t * x)
{
return (uint16_t)(x[0] << 0) | (uint16_t)(x[1] << 8);
}
It generates a false warning when there is a shift by 0 and no warning when
x[0] is shifted by other value:
$ g++ -c -Wconversion -Wall -Wextra foo.cpp
foo.cpp: In function ‘uint16_t foo(uint8_t*)’:
foo.cpp:5:31: warning: conversion to ‘uint16_t {aka short unsigned int}’ from
‘int’ may alter its value [-Wconversion]
return (uint16_t)(x[0] << 0) | (uint16_t)(x[1] << 8);
$ g++ --version
g++ (Ubuntu/Linaro 4.8.2-8) 4.8.2
Copyright (C) 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.