From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11321 invoked by alias); 10 Apr 2013 15:48:21 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 11303 invoked by uid 48); 10 Apr 2013 15:48:18 -0000 From: "hniksic at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/56908] New: Spurious warning when XOR-ing uint8_t values Date: Wed, 10 Apr 2013 15:48:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: hniksic at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 X-SW-Source: 2013-04/txt/msg00860.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56908 Bug #: 56908 Summary: Spurious warning when XOR-ing uint8_t values Classification: Unclassified Product: gcc Version: 4.7.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned@gcc.gnu.org ReportedBy: hniksic@gmail.com g++ -Wconversion displays what I believe is a spurious warning in my code: warning: conversion to 'uint8_t {aka unsigned char}' from 'int' may alter its value [-Wconversion] -Wconversion is mandated by the project I'm working on. Since I'm striving for warningless compilation, I looked into the function. Even after a careful examination, I cannot find fault with it, nor an obvious way to get rid of the warning without compromising the code's readability. The minimal example that warns is: #include #include void xorblock(uint8_t* dest, const uint8_t* src, size_t len) { while (len--) *dest++ ^= *src++; } Compiled with g++ -Wconversion a.cc, it prints the warning as: a.cc: In function 'void xorblock(uint8_t*, const uint8_t*, size_t)': a.cc:8:20: warning: conversion to 'uint8_t {aka unsigned char}' from 'int' may alter its value [-Wconversion] Both operands have the same type, which is appropriate for the calculation. Casting the right-hand side of the compound assignment to either int, uint8_t, or unsigned int fails to silence the warning. The warning does not occur with gcc, only with g++. The only way I found to remove the warning is to rewrite the assignment as a non-compound assignment. But this precludes the use of the post-increment operator and consequently makes the function harder to follow. (In this case shorter is more readable, as *dest++ = *src++ is one of the most widely understood C idioms.) The warning happens with g++ 4.7 and 4.8, but not with g++ 4.6 series.