aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorGabriel Dos Reis <gdr@integrable-solutions.net>2005-06-09 22:21:48 +0000
committerGabriel Dos Reis <gdr@gcc.gnu.org>2005-06-09 22:21:48 +0000
commitb7e20b53f60d973debcd771c882cc44b13db38b1 (patch)
tree5ba1ed694692d32697b04063c0e9fb9c31bfdbd2 /gcc
parent92f5e87c2ba9b5f83b8b465a43e43d41a2801265 (diff)
downloadgcc-b7e20b53f60d973debcd771c882cc44b13db38b1.zip
gcc-b7e20b53f60d973debcd771c882cc44b13db38b1.tar.gz
gcc-b7e20b53f60d973debcd771c882cc44b13db38b1.tar.bz2
re PR c/21759 (Implement warning for codes at the intersection of C and C++)
PR c/21759 * c.opt (Wc++-compat): New. * doc/invoke.texi (-Wc++-compat): Document. * c-typeck.c (convert_for_assignment): Check for implicit conversion void* -> T*. testsuite/ * gcc.dg/Wcxx-compat-1.c: New. From-SVN: r100806
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog8
-rw-r--r--gcc/c-typeck.c12
-rw-r--r--gcc/c.opt5
-rw-r--r--gcc/doc/invoke.texi7
-rw-r--r--gcc/testsuite/ChangeLog4
-rw-r--r--gcc/testsuite/gcc.dg/Wcxx-compat-1.c11
6 files changed, 46 insertions, 1 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 77b50d8..3c9b760 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,11 @@
+2005-06-09 Gabriel Dos Reis <gdr@integrable-solutions.net>
+
+ PR c/21759
+ * c.opt (Wc++-compat): New.
+ * doc/invoke.texi (-Wc++-compat): Document.
+ * c-typeck.c (convert_for_assignment): Check for implicit
+ conversion void* -> T*.
+
2005-06-09 Gabriel Dos Reis <gdr@cs.tamu.edu>
* machmode.h (to_machine_mode): New.
diff --git a/gcc/c-typeck.c b/gcc/c-typeck.c
index 9429b73..918afa0 100644
--- a/gcc/c-typeck.c
+++ b/gcc/c-typeck.c
@@ -3779,6 +3779,18 @@ convert_for_assignment (tree type, tree rhs, enum impl_conv errtype,
|| targetm.vector_opaque_p (rhstype))
&& TREE_CODE (ttl) == VECTOR_TYPE
&& TREE_CODE (ttr) == VECTOR_TYPE;
+
+ /* C++ does not allow the implicit conversion void* -> T*. However,
+ for the purpose of reducing the number of false positives, we
+ tolerate the special case of
+
+ int *p = NULL;
+
+ where NULL is typically defined in C to be '(void *) 0'. */
+ if (OPT_Wc___compat && VOID_TYPE_P (ttr) && rhs != null_pointer_node
+ && !VOID_TYPE_P (ttl))
+ warning (OPT_Wc___compat, "request for implicit conversion from "
+ "%qT to %qT not permitted in C++", rhstype, type);
/* Any non-function converts to a [const][volatile] void *
and vice versa; otherwise, targets must be the same.
diff --git a/gcc/c.opt b/gcc/c.opt
index a055216..ef8705d 100644
--- a/gcc/c.opt
+++ b/gcc/c.opt
@@ -128,6 +128,11 @@ Wbad-function-cast
C ObjC Var(warn_bad_function_cast)
Warn about casting functions to incompatible types
+Wc++-compat
+C Var(warn_cxx_compat)
+Warn about C constructs that are not in the common subset of C and C++
+
+
Wcast-qual
C ObjC C++ ObjC++ Var(warn_cast_qual)
Warn about casts which discard qualifiers
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index eef9a0f..95846f1 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -219,7 +219,7 @@ Objective-C and Objective-C++ Dialects}.
@xref{Warning Options,,Options to Request or Suppress Warnings}.
@gccoptlist{-fsyntax-only -pedantic -pedantic-errors @gol
-w -Wextra -Wall -Waggregate-return -Wno-attributes @gol
--Wcast-align -Wcast-qual -Wchar-subscripts -Wcomment @gol
+-Wc++-compat -Wcast-align -Wcast-qual -Wchar-subscripts -Wcomment @gol
-Wconversion -Wno-deprecated-declarations @gol
-Wdisabled-optimization -Wno-div-by-zero -Wno-endif-labels @gol
-Werror -Werror-implicit-function-declaration @gol
@@ -2993,6 +2993,11 @@ to functions.
Warn whenever a function call is cast to a non-matching type.
For example, warn if @code{int malloc()} is cast to @code{anything *}.
+@item -Wc++-compat
+Warn about ISO C constructs that are outside of the common subset of
+ISO C and ISO C++, e.g.@: request for implicit conversion from
+@code{void *} to a pointer to non-@code{void} type.
+
@item -Wcast-qual
@opindex Wcast-qual
Warn whenever a pointer is cast so as to remove a type qualifier from
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 92f5a67..7fc18e9 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,7 @@
+2005-06-09 Gabriel Dos Reis <gdr@integrable-solutions.net>
+
+ * gcc.dg/Wcxx-compat-1.c: New.
+
2005-06-09 Thomas Koenig <Thomas.Koenig@online.de>
PR libfortran/21480
diff --git a/gcc/testsuite/gcc.dg/Wcxx-compat-1.c b/gcc/testsuite/gcc.dg/Wcxx-compat-1.c
new file mode 100644
index 0000000..9150042
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/Wcxx-compat-1.c
@@ -0,0 +1,11 @@
+/* PR c/21759 */
+/* { dg-options "-Wc++-compat" } */
+
+int
+main(void)
+{
+ void *p = 0;
+ int *q = p; /* { dg-warning "not permitted" } */
+ double* t = (void *)0;
+ return p != q;
+}