This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
Other format: | [Raw text] |
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.
Attachment:
fix-pr37004.diff
Description: Text document
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |