aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp
diff options
context:
space:
mode:
authorManuel López-Ibáñez <manu@gcc.gnu.org>2007-03-16 23:32:12 +0000
committerManuel López-Ibáñez <manu@gcc.gnu.org>2007-03-16 23:32:12 +0000
commit07231d4f834e1286c28f28bd18065fdde30912ba (patch)
tree5a95c9649676f7d06f094cc2fa3481529f14eef5 /gcc/cp
parentaefd26064caa4f8e041540679169265d74e8f3fd (diff)
downloadgcc-07231d4f834e1286c28f28bd18065fdde30912ba.zip
gcc-07231d4f834e1286c28f28bd18065fdde30912ba.tar.gz
gcc-07231d4f834e1286c28f28bd18065fdde30912ba.tar.bz2
invoke.texi (-Wconversion): Document warnings specific to C++.
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. From-SVN: r123005
Diffstat (limited to 'gcc/cp')
-rw-r--r--gcc/cp/ChangeLog12
-rw-r--r--gcc/cp/call.c22
-rw-r--r--gcc/cp/cp-tree.h1
-rw-r--r--gcc/cp/cvt.c23
-rw-r--r--gcc/cp/typeck.c4
5 files changed, 44 insertions, 18 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 730c59e..f5d26c0 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,15 @@
+2007-03-16 Manuel Lopez-Ibanez <manu@gcc.gnu.org>
+
+ * 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.
+
2007-03-15 Manuel Lopez-Ibanez <manu@gcc.gnu.org>
PR c++/30891
diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index 9d25298..8218ed4 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -4245,11 +4245,12 @@ build_temp (tree expr, tree type, int flags,
return expr;
}
-/* Perform warnings about conversion of EXPR to type TOTYPE.
+/* Perform warnings about peculiar, but valid, conversions from/to NULL.
+ EXPR is implicitly converted to type TOTYPE.
FN and ARGNUM are used for diagnostics. */
static void
-convert_conversion_warnings (tree totype, tree expr, tree fn, int argnum)
+conversion_null_warnings (tree totype, tree expr, tree fn, int argnum)
{
tree t = non_reference (totype);
@@ -4263,19 +4264,8 @@ convert_conversion_warnings (tree totype, tree expr, tree fn, int argnum)
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))
+ else 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);
@@ -4328,7 +4318,7 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum,
}
if (issue_conversion_warnings)
- convert_conversion_warnings (totype, expr, fn, argnum);
+ conversion_null_warnings (totype, expr, fn, argnum);
switch (convs->kind)
{
@@ -4415,7 +4405,7 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum,
expr = convert_like_real (convs->u.next, expr, fn, argnum,
convs->kind == ck_ref_bind ? -1 : 1,
- /*issue_conversion_warnings=*/false,
+ convs->kind == ck_ref_bind ? issue_conversion_warnings : false,
c_cast_p);
if (expr == error_mark_node)
return error_mark_node;
diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index 7d6ebc7..b9b3500 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -4049,6 +4049,7 @@ extern tree convert_from_reference (tree);
extern tree force_rvalue (tree);
extern tree ocp_convert (tree, tree, int, int);
extern tree cp_convert (tree, tree);
+extern tree cp_convert_and_check (tree, tree);
extern tree convert_to_void (tree, const char */*implicit context*/);
extern tree convert_force (tree, tree, int);
extern tree build_expr_type_conversion (int, tree, bool);
diff --git a/gcc/cp/cvt.c b/gcc/cp/cvt.c
index 4e628a5..947f1f2 100644
--- a/gcc/cp/cvt.c
+++ b/gcc/cp/cvt.c
@@ -593,6 +593,29 @@ cp_convert (tree type, tree expr)
return ocp_convert (type, expr, CONV_OLD_CONVERT, LOOKUP_NORMAL);
}
+/* C++ equivalent of convert_and_check but using cp_convert as the
+ conversion function.
+
+ 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
+cp_convert_and_check (tree type, tree expr)
+{
+ tree result;
+
+ if (TREE_TYPE (expr) == type)
+ return expr;
+
+ result = cp_convert (type, expr);
+
+ if (!skip_evaluation && !TREE_OVERFLOW_P (expr))
+ warnings_for_convert_and_check (type, expr, result);
+
+ return result;
+}
+
/* Conversion...
FLAGS indicates how we should behave. */
diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c
index ac6eb2b..6478b37 100644
--- a/gcc/cp/typeck.c
+++ b/gcc/cp/typeck.c
@@ -3837,9 +3837,9 @@ build_binary_op (enum tree_code code, tree orig_op0, tree orig_op1,
if (! converted)
{
if (TREE_TYPE (op0) != result_type)
- op0 = cp_convert (result_type, op0);
+ op0 = cp_convert_and_check (result_type, op0);
if (TREE_TYPE (op1) != result_type)
- op1 = cp_convert (result_type, op1);
+ op1 = cp_convert_and_check (result_type, op1);
if (op0 == error_mark_node || op1 == error_mark_node)
return error_mark_node;