aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorManuel López-Ibáñez <manu@gcc.gnu.org>2010-04-09 07:49:41 +0000
committerManuel López-Ibáñez <manu@gcc.gnu.org>2010-04-09 07:49:41 +0000
commitdc8d273907ba88cf11180a2fdf79f086feeb44f6 (patch)
treed3948de1f31acd50882bef52bb6d0f63b19293a6 /gcc
parentd3a9eea2c0e65e0f03c249bab8aa3fa56149dfe0 (diff)
downloadgcc-dc8d273907ba88cf11180a2fdf79f086feeb44f6.zip
gcc-dc8d273907ba88cf11180a2fdf79f086feeb44f6.tar.gz
gcc-dc8d273907ba88cf11180a2fdf79f086feeb44f6.tar.bz2
re PR c++/28584 (Cast to pointer from integer of different size)
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++. 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. From-SVN: r158150
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog6
-rw-r--r--gcc/c.opt2
-rw-r--r--gcc/cp/ChangeLog6
-rw-r--r--gcc/cp/typeck.c9
-rw-r--r--gcc/doc/invoke.texi6
-rw-r--r--gcc/testsuite/ChangeLog12
-rw-r--r--gcc/testsuite/c-c++-common/Wint-to-pointer-cast-1.c (renamed from gcc/testsuite/gcc.dg/Wint-to-pointer-cast-1.c)0
-rw-r--r--gcc/testsuite/c-c++-common/Wint-to-pointer-cast-2.c (renamed from gcc/testsuite/gcc.dg/Wint-to-pointer-cast-2.c)0
-rw-r--r--gcc/testsuite/c-c++-common/Wint-to-pointer-cast-3.c (renamed from gcc/testsuite/gcc.dg/Wint-to-pointer-cast-3.c)4
-rw-r--r--gcc/testsuite/g++.dg/other/increment1.C1
-rw-r--r--gcc/testsuite/g++.old-deja/g++.mike/warn1.C2
11 files changed, 43 insertions, 5 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 9b1c69e..23377d1 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,9 @@
+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.
diff --git a/gcc/c.opt b/gcc/c.opt
index a148208..973acf4 100644
--- a/gcc/c.opt
+++ b/gcc/c.opt
@@ -277,7 +277,7 @@ Wimport
C ObjC C++ ObjC++ Undocumented
Wint-to-pointer-cast
-C ObjC Var(warn_int_to_pointer_cast) Init(1) Warning
+C ObjC C++ ObjC++ Var(warn_int_to_pointer_cast) Init(1) Warning
Warn when there is a cast to a pointer from an integer of a different size
Winvalid-offsetof
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index fa01fcb..c40e368 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,9 @@
+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
diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c
index f623717..383754b 100644
--- a/gcc/cp/typeck.c
+++ b/gcc/cp/typeck.c
@@ -6289,6 +6289,15 @@ cp_build_c_cast (tree type, tree expr, tsubst_flags_t complain)
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);
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 7a8ca55..ad7d097 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -4284,11 +4284,13 @@ warning about it.
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
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 5b77482..17277cf 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,15 @@
+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
diff --git a/gcc/testsuite/gcc.dg/Wint-to-pointer-cast-1.c b/gcc/testsuite/c-c++-common/Wint-to-pointer-cast-1.c
index a7687a6..a7687a6 100644
--- a/gcc/testsuite/gcc.dg/Wint-to-pointer-cast-1.c
+++ b/gcc/testsuite/c-c++-common/Wint-to-pointer-cast-1.c
diff --git a/gcc/testsuite/gcc.dg/Wint-to-pointer-cast-2.c b/gcc/testsuite/c-c++-common/Wint-to-pointer-cast-2.c
index 5546abb..5546abb 100644
--- a/gcc/testsuite/gcc.dg/Wint-to-pointer-cast-2.c
+++ b/gcc/testsuite/c-c++-common/Wint-to-pointer-cast-2.c
diff --git a/gcc/testsuite/gcc.dg/Wint-to-pointer-cast-3.c b/gcc/testsuite/c-c++-common/Wint-to-pointer-cast-3.c
index f4309a9..052ab37 100644
--- a/gcc/testsuite/gcc.dg/Wint-to-pointer-cast-3.c
+++ b/gcc/testsuite/c-c++-common/Wint-to-pointer-cast-3.c
@@ -16,5 +16,7 @@ void *p;
char
g (void)
{
- return (char) p; /* { dg-warning "cast from pointer to integer of different size" } */
+ return (char) p;
+/* { dg-warning "cast from pointer to integer of different size" "" { target c } 19 } */
+/* { dg-error "cast from 'void\\*' to 'char' loses precision" "" { target c++ } 19 } */
}
diff --git a/gcc/testsuite/g++.dg/other/increment1.C b/gcc/testsuite/g++.dg/other/increment1.C
index c36e573..506157e 100644
--- a/gcc/testsuite/g++.dg/other/increment1.C
+++ b/gcc/testsuite/g++.dg/other/increment1.C
@@ -1,5 +1,6 @@
// PR c++/37561
// { dg-do compile }
+// { dg-options "-Wno-int-to-pointer-cast" }
__PTRDIFF_TYPE__ p;
char q;
diff --git a/gcc/testsuite/g++.old-deja/g++.mike/warn1.C b/gcc/testsuite/g++.old-deja/g++.mike/warn1.C
index 52059cb..5d6fdec 100644
--- a/gcc/testsuite/g++.old-deja/g++.mike/warn1.C
+++ b/gcc/testsuite/g++.old-deja/g++.mike/warn1.C
@@ -1,5 +1,5 @@
// { dg-do assemble }
-// { dg-options "-Wall" }
+// { dg-options "-Wall -Wno-int-to-pointer-cast" }
typedef char * charptr;
typedef __SIZE_TYPE__ size_t;