OSDN Git Service

PR c/21759
authorgdr <gdr@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 9 Jun 2005 22:21:48 +0000 (22:21 +0000)
committergdr <gdr@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 9 Jun 2005 22:21:48 +0000 (22:21 +0000)
        * 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.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@100806 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/c-typeck.c
gcc/c.opt
gcc/doc/invoke.texi
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/Wcxx-compat-1.c [new file with mode: 0644]

index 77b50d8..3c9b760 100644 (file)
@@ -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.
index 9429b73..918afa0 100644 (file)
@@ -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.
index a055216..ef8705d 100644 (file)
--- 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
index eef9a0f..95846f1 100644 (file)
@@ -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
index 92f5a67..7fc18e9 100644 (file)
@@ -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 (file)
index 0000000..9150042
--- /dev/null
@@ -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;
+}