PR c++/37004 Wconversion warns for short y = 0x7fff; short z = (short) x & y;
Manuel López-Ibáñez
lopezibanez@gmail.com
Wed Aug 27 14:02:00 GMT 2008
The code in c-common.c calls a function common_type that is expected
to not perform promotion of their operands. However, C++ does perform
promotion, so optimizations like shorten_binary_op do not work.
-Wconversion relies on this function to detect that cases like:
void foo (short x)
{
short y = 0x7fff;
short z = (short) x & y;
}
are safe.
The current patch modifies common_type to work more like its C
version. To do so, it adds a new static function cp_common_type that
behaves like type_after_usual_arithmetic_conversions but does not
perform default promotions. The function
type_after_usual_arithmetic_conversions is modified to use
cp_common_type instead of duplicating code.
The old common_type was only called twice within cp/, once for
arithmetic types that were already promoted, this is replaced by
cp_common_type, and for pointer types, this is replaced by a new
function common_pointer_type.
Bootstrapped and regression tested on x86_64-unknown-linux-gnu with
--enable-languages=all,ada
OK for trunk?
2008-08-26 Manuel Lopez-Ibanez <manu@gcc.gnu.org>
PR c++/37004
cp/
* typeck.c (cp_common_type): New. The same as
type_after_usual_arithmetic_conversions but without promotions.
(type_after_usual_arithmetic_conversions): Do the promotions and
call cp_common_type.
(common_type): Make it behave like the C version of this
function. Do not handle pointer types.
(common_pointer_type): Move handling of pointer types from
common_type to here.
(cp_build_binary_op): Use common_pointer_type instead of
common_type in call to pointer_diff.
Use cp_common_type instead of common_type.
* cp-tree.h (common_pointer_type): Declare.
testsuite/
* g++.dg/warn/Wconversion-pr34389.C: Remove XFAIL.
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: fix-pr37004.diff
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20080827/baac5309/attachment.ksh>
More information about the Gcc-patches
mailing list