PR c++/28584
* c.opt (Wint-to-pointer-cast): Available in C++.
* doc/invoke.texi (Wint-to-pointer-cast): Available in C++.
cp/
* typeck.c (cp_build_c_cast): Warn for casting integer to larger
pointer type.
testsuite/
* gcc.dg/Wint-to-pointer-cast-1.c: Move to...
* c-c++-common/Wint-to-pointer-cast-1.c: ... here.
* gcc.dg/Wint-to-pointer-cast-2.c: Move to...
* c-c++-common/Wint-to-pointer-cast-2.c: ... here.
* gcc.dg/Wint-to-pointer-cast-3.c: Move to...
* c-c++-common/Wint-to-pointer-cast-3.c: ... here. Update.
* g++.old-deja/g++.mike/warn1.C: Add -Wno-int-to-pointer-cast.
* g++.dg/other/increment1.C: Likewise.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@158150
138bc75d-0d04-0410-961f-
82ee72b054a4
+2010-04-09 Manuel López-Ibáñez <manu@gcc.gnu.org>
+
+ PR c++/28584
+ * c.opt (Wint-to-pointer-cast): Available in C++.
+ * doc/invoke.texi (Wint-to-pointer-cast): Available in C++.
+
2010-04-08 Eric Botcazou <ebotcazou@adacore.com>
* tree.h (TREE_ADDRESSABLE): Document its effect for function types.
+2010-04-09 Manuel López-Ibáñez <manu@gcc.gnu.org>
+
+ PR c++/28584
+ * typeck.c (cp_build_c_cast): Warn for casting integer to larger
+ pointer type.
+
2010-04-07 Jason Merrill <jason@redhat.com>
PR c++/43016
return error_mark_node;
}
+ if (TREE_CODE (type) == POINTER_TYPE
+ && TREE_CODE (TREE_TYPE (value)) == INTEGER_TYPE
+ /* Casting to an integer of smaller size is an error detected elsewhere. */
+ && TYPE_PRECISION (type) > TYPE_PRECISION (TREE_TYPE (value))
+ /* Don't warn about converting any constant. */
+ && !TREE_CONSTANT (value))
+ warning_at (input_location, OPT_Wint_to_pointer_cast,
+ "cast to pointer from integer of different size");
+
/* A C-style cast can be a const_cast. */
result = build_const_cast_1 (type, value, /*complain=*/false,
&valid_p);
The restrictions on @samp{offsetof} may be relaxed in a future version
of the C++ standard.
-@item -Wno-int-to-pointer-cast @r{(C and Objective-C only)}
+@item -Wno-int-to-pointer-cast
@opindex Wno-int-to-pointer-cast
@opindex Wint-to-pointer-cast
Suppress warnings from casts to pointer type of an integer of a
-different size.
+different size. In C++, casting to a pointer type of smaller size is
+an error. @option{Wint-to-pointer-cast} is enabled by default.
+
@item -Wno-pointer-to-int-cast @r{(C and Objective-C only)}
@opindex Wno-pointer-to-int-cast
+2010-04-09 Manuel López-Ibáñez <manu@gcc.gnu.org>
+
+ PR c++/28584
+ * gcc.dg/Wint-to-pointer-cast-1.c: Move to...
+ * c-c++-common/Wint-to-pointer-cast-1.c: ... here.
+ * gcc.dg/Wint-to-pointer-cast-2.c: Move to...
+ * c-c++-common/Wint-to-pointer-cast-2.c: ... here.
+ * gcc.dg/Wint-to-pointer-cast-3.c: Move to...
+ * c-c++-common/Wint-to-pointer-cast-3.c: ... here. Update.
+ * g++.old-deja/g++.mike/warn1.C: Add -Wno-int-to-pointer-cast.
+ * g++.dg/other/increment1.C: Likewise.
+
2010-04-09 Tobias Burnus <burnus@net-b.de>
PR fortran/18918
+++ /dev/null
-/* Test -Wpointer-to-int-cast. */
-/* Origin: Joseph Myers <joseph@codesourcery.com> */
-/* { dg-do compile } */
-/* { dg-options "-Wpointer-to-int-cast" } */
-
-void *p;
-
-char
-f (void)
-{
- return (char) p; /* { dg-warning "cast from pointer to integer of different size" } */
-}
+++ /dev/null
-/* Test -Wno-pointer-to-int-cast. */
-/* Origin: Joseph Myers <joseph@codesourcery.com> */
-/* { dg-do compile } */
-/* { dg-options "-Wno-pointer-to-int-cast" } */
-
-void *p;
-
-char
-f (void)
-{
- return (char) p;
-}
-
-
-char c;
-
-void *
-g (void)
-{
- return (void *) c; /* { dg-warning "cast to pointer from integer of different size" } */
-}