This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/37004] [C++ only] Wconversion warns for short y = 0x7fff; short z = (short) x & y;
- From: "manu at gcc dot gnu dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 23 Aug 2008 18:06:07 -0000
- Subject: [Bug c++/37004] [C++ only] Wconversion warns for short y = 0x7fff; short z = (short) x & y;
- References: <bug-37004-13511@http.gcc.gnu.org/bugzilla/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Comment #3 from manu at gcc dot gnu dot org 2008-08-23 18:06 -------
In C:
/* Wrapper around c_common_type that is used by c-common.c and other
front end optimizations that remove promotions. ENUMERAL_TYPEs
are allowed here and are converted to their compatible integer types.
BOOLEAN_TYPEs are allowed here and return either boolean_type_node or
preferably a non-Boolean type as the common type. */
tree
common_type (tree t1, tree t2)
In C++:
/* Return the common type of two types.
We assume that comptypes has already been done and returned 1;
if that isn't so, this may crash.
This is the type for the result of most arithmetic operations
if the operands have the given two types. */
tree
common_type (tree t1, tree t2)
They are not the same. C++ performs integral promotion, C doesn't. Which is a
waste of time in C++ because everywhere common_type is called, integral
promotions have been performed already.
Duplicationg type_after_usual_arithmetic_conversions with a variant that does
not perform promotions fixes the problem. But there should be a more elegant
way to handle this than just duplicating the whole function...
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37004