diff options
author | manu <manu@138bc75d-0d04-0410-961f-82ee72b054a4> | 2007-03-16 23:32:12 +0000 |
---|---|---|
committer | manu <manu@138bc75d-0d04-0410-961f-82ee72b054a4> | 2007-03-16 23:32:12 +0000 |
commit | 59dd8856eb0c8646db46941140467a5e342cec54 (patch) | |
tree | 5a95c9649676f7d06f094cc2fa3481529f14eef5 /gcc/c-common.c | |
parent | ec94117da0f841107969a49cce421312f5cbd298 (diff) | |
download | gcc-59dd8856eb0c8646db46941140467a5e342cec54.tar.gz |
2007-03-16 Manuel Lopez-Ibanez <manu@gcc.gnu.org>
* doc/invoke.texi (-Wconversion): Document warnings specific to C++.
* c-common.c (convert_and_check): Move warning logic to...
(warnings_for_convert_and_check): ...here. Define.
* c-common.h (warnings_for_convert_and_check): Declare.
cp/
* cvt.c (cp_convert_and_check) : Define.
* cp-tree.h (cp_convert_and_check): Declare.
* call.c (convert_conversion_warnings): Rename to
conversion_null_warnings. The warning for floating-point to
integer is handled by convert_and_check in convert_like_real.
(convert_like_real): convert_conversion_warnings was renamed as
conversion_null_warnings.
* typeck.c (build_binary_op): Use cp_convert_and_check to warn for
overflow and changes of value during conversion.
testsuite/
* g++.dg/warn/Wconversion-integer.C: New
* g++.dg/warn/Wconversion-real.C: New.
* g++.dg/warn/Wconversion-real-integer.C: New.
* g++.dg/warn/conv2.C: Updated.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@123005 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/c-common.c')
-rw-r--r-- | gcc/c-common.c | 41 |
1 files changed, 25 insertions, 16 deletions
diff --git a/gcc/c-common.c b/gcc/c-common.c index 36b87eba206..8f71e6916ed 100644 --- a/gcc/c-common.c +++ b/gcc/c-common.c @@ -1168,7 +1168,7 @@ vector_types_convertible_p (tree t1, tree t2, bool emit_lax_note) } /* Warns if the conversion of EXPR to TYPE may alter a value. - This function is called from convert_and_check. */ + This is a helper function for warnings_for_convert_and_check. */ static void conversion_warning (tree type, tree expr) @@ -1276,23 +1276,13 @@ conversion_warning (tree type, tree expr) } } -/* Convert EXPR to TYPE, warning about conversion problems with constants. - Invoke this function on every expression that is converted implicitly, - i.e. because of language rules and not because of an explicit cast. */ +/* Produce warnings after a conversion. RESULT is the result of + converting EXPR to TYPE. This is a helper function for + convert_and_check and cp_convert_and_check. */ -tree -convert_and_check (tree type, tree expr) +void +warnings_for_convert_and_check (tree type, tree expr, tree result) { - tree result; - - if (TREE_TYPE (expr) == type) - return expr; - - result = convert (type, expr); - - if (skip_evaluation || TREE_OVERFLOW_P (expr)) - return result; - if (TREE_CODE (expr) == INTEGER_CST && (TREE_CODE (type) == INTEGER_TYPE || TREE_CODE (type) == ENUMERAL_TYPE) @@ -1332,7 +1322,26 @@ convert_and_check (tree type, tree expr) "overflow in implicit constant conversion"); else if (warn_conversion) conversion_warning (type, expr); +} + + +/* Convert EXPR to TYPE, warning about conversion problems with constants. + Invoke this function on every expression that is converted implicitly, + i.e. because of language rules and not because of an explicit cast. */ + +tree +convert_and_check (tree type, tree expr) +{ + tree result; + + if (TREE_TYPE (expr) == type) + return expr; + result = convert (type, expr); + + if (!skip_evaluation && !TREE_OVERFLOW_P (expr)) + warnings_for_convert_and_check (type, expr, result); + return result; } |