https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61760

            Bug ID: 61760
           Summary: -Wconversion inconsistency between gcc and g++
           Product: gcc
           Version: 4.9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: js at alien8 dot de

Given the code:

unsigned char foo(unsigned char x)
{
    return x >> 1;
}

If you compile this with 'gcc -Wconversion -c foo.c', there is no warning. If
you compile it with 'g++ -Wconversion -c foo.c' you get:

foo.c:3:11: warning: conversion to ‘unsigned char’ from ‘int’ may alter its
value [-Wconversion]
  return x >> 1;

I would argue that the conversion warning is false in both cases, because there
is no information loss involved, even though the intermediate result is cast to
an int.

Is there a reason why g++ produces the warning here or is this a bug?

This happens using 4.8.3 and 4.9.1 20140706 (prerelease) on x86_64.

Reply via email to