g++-4.3.0 -ansi -pedantic-errors -std=c++0x -Wall -Wconversion issues the following diagnostic on the following code:
// test case: typedef unsigned short ushort; enum { FOO = 0x13 }; template <typename T> inline void andnot(T& lv, T&& rv) { lv &= ~rv; } template <typename T> inline void andnot(T& lv, const T& rv) { lv &= ~rv; } int main(int, char*[]) { ushort x = 99; x = ~FOO; x &= ~FOO; // -Wconversion x = x & ~FOO; // -Wconversion x = x & ushort(~FOO); // -Wconversion x = x & ushort(~ushort(FOO)); // -Wconversion x &= static_cast<ushort>(~FOO); // -Wconversion x &= ~x; // andnot(x, FOO); // no match andnot(x, ushort(FOO)); // -Wconversion return x; } // end test case. ../../../src/conv.cc: In function 'int main(int, char**)': ../../../src/conv.cc:25: warning: conversion to 'ushort' from 'int' may alter its value ../../../src/conv.cc:26: warning: conversion to 'ushort' from 'int' may alter its value ../../../src/conv.cc:27: warning: conversion to 'ushort' from 'int' may alter its value ../../../src/conv.cc:28: warning: conversion to 'ushort' from 'int' may alter its value ../../../src/conv.cc:29: warning: conversion to 'ushort' from 'int' may alter its value ../../../src/conv.cc: In function 'void andnot(T&, T&&) [with T = ushort]': ../../../src/conv.cc:32: instantiated from here ../../../src/conv.cc:11: warning: conversion to 'short unsigned int' from 'int' may alter its value All warnings disappear if -Wconversion is omitted. I don't understand the rationale why some of the above lines are diagnostic free (assignments), and others trigger the diagnostic, so I cannot claim which are valid w.r.t. -Wconversion. I did however expect a function-style (ctor-style) cast or static_cast to suppress the diagnostic. Is there a bug, or proper "workaround" to locally suppress the diagnostic? keywords: diagnostic -- Summary: -Wconversion rejects bitwise negation and assignment, cannot cast around Product: gcc Version: 4.3.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: fang at csl dot cornell dot edu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35852