diff options
author | Dirk Mueller <dmueller@suse.de> | 2007-03-14 23:17:03 +0000 |
---|---|---|
committer | Dirk Mueller <mueller@gcc.gnu.org> | 2007-03-14 23:17:03 +0000 |
commit | 1f7f19c46a9fa0c1be528bfb9fa54196d8ca0e4b (patch) | |
tree | 8e42b3900511ae86a0c8d657b74dc47806b4ff03 /gcc/cp/call.c | |
parent | ddff69b97240cf4e679423ecf6973ab97ddde0ed (diff) | |
download | gcc-1f7f19c46a9fa0c1be528bfb9fa54196d8ca0e4b.zip gcc-1f7f19c46a9fa0c1be528bfb9fa54196d8ca0e4b.tar.gz gcc-1f7f19c46a9fa0c1be528bfb9fa54196d8ca0e4b.tar.bz2 |
re PR c++/30860 (Should warn about boolean constant false used in pointer context)
2007-03-15 Dirk Mueller <dmueller@suse.de>
PR c++/30860
* call.c (convert_conversion_warnings): New..
(convert_like_real): .. factored out from here.
(convert_conversion_warnings): Add warning about
false being converted to NULL in argument passing.
* g++.dg/warn/Wconversion2.C: New.
From-SVN: r122934
Diffstat (limited to 'gcc/cp/call.c')
-rw-r--r-- | gcc/cp/call.c | 60 |
1 files changed, 36 insertions, 24 deletions
diff --git a/gcc/cp/call.c b/gcc/cp/call.c index 00e0c06..53129bb 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -4245,6 +4245,41 @@ build_temp (tree expr, tree type, int flags, return expr; } +/* Perform warnings about conversion of EXPR to type TOTYPE. + FN and ARGNUM are used for diagnostics. */ + +static void +convert_conversion_warnings (tree totype, tree expr, tree fn, int argnum) +{ + tree t = non_reference (totype); + + /* Issue warnings about peculiar, but valid, uses of NULL. */ + if (expr == null_node && TREE_CODE (t) != BOOLEAN_TYPE && ARITHMETIC_TYPE_P (t)) + { + if (fn) + warning (OPT_Wconversion, "passing NULL to non-pointer argument %P of %qD", + argnum, fn); + else + warning (OPT_Wconversion, "converting to non-pointer type %qT from NULL", t); + } + + /* Warn about assigning a floating-point type to an integer type. */ + if (TREE_CODE (TREE_TYPE (expr)) == REAL_TYPE + && TREE_CODE (t) == INTEGER_TYPE) + { + if (fn) + warning (OPT_Wconversion, "passing %qT for argument %P to %qD", + TREE_TYPE (expr), argnum, fn); + else + warning (OPT_Wconversion, "converting to %qT from %qT", t, TREE_TYPE (expr)); + } + + /* Issue warnings if "false" is converted to a NULL pointer */ + if (expr == boolean_false_node && fn && POINTER_TYPE_P (t)) + warning (OPT_Wconversion, + "converting %<false%> to pointer type for argument %P of %qD", + argnum, fn); +} /* Perform the conversions in CONVS on the expression EXPR. FN and ARGNUM are used for diagnostics. ARGNUM is zero based, -1 @@ -4293,30 +4328,7 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum, } if (issue_conversion_warnings) - { - tree t = non_reference (totype); - - /* Issue warnings about peculiar, but valid, uses of NULL. */ - if (expr == null_node && TREE_CODE (t) != BOOLEAN_TYPE && ARITHMETIC_TYPE_P (t)) - { - if (fn) - warning (OPT_Wconversion, "passing NULL to non-pointer argument %P of %qD", - argnum, fn); - else - warning (OPT_Wconversion, "converting to non-pointer type %qT from NULL", t); - } - - /* Warn about assigning a floating-point type to an integer type. */ - if (TREE_CODE (TREE_TYPE (expr)) == REAL_TYPE - && TREE_CODE (t) == INTEGER_TYPE) - { - if (fn) - warning (OPT_Wconversion, "passing %qT for argument %P to %qD", - TREE_TYPE (expr), argnum, fn); - else - warning (OPT_Wconversion, "converting to %qT from %qT", t, TREE_TYPE (expr)); - } - } + convert_conversion_warnings (totype, expr, fn, argnum); switch (convs->kind) { |