This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: PATCH to C front-end: PR 21759
"Joseph S. Myers" <joseph@codesourcery.com> writes:
| On Thu, 9 Jun 2005, Gabriel Dos Reis wrote:
|
| > + if (warn_cxx_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);
|
| It's not clear this is a case which needs the "if (warn_...) rather than
| just controlling the warning through the first argument to warning.
|
| > + @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
|
| Should be "e.g.," or "e.g.@:".
|
| > Index: testsuite/gcc.dg/Wcxx-compat-1.c
|
| Should also test the special case of not warning for conversion of
| (void *)0.
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*.
testsuite/
2005-06-09 Gabriel Dos Reis <gdr@integrable-solutions.net>
* gcc.dg/Wcxx-compat-1.c: New.
Index: c-typeck.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-typeck.c,v
retrieving revision 1.451
diff -p -r1.451 c-typeck.c
*** c-typeck.c 9 Jun 2005 11:35:46 -0000 1.451
--- c-typeck.c 9 Jun 2005 17:46:43 -0000
*************** convert_for_assignment (tree type, tree
*** 3779,3784 ****
--- 3779,3796 ----
|| 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: c.opt
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c.opt,v
retrieving revision 1.45
diff -p -r1.45 c.opt
*** c.opt 25 May 2005 03:58:57 -0000 1.45
--- c.opt 9 Jun 2005 17:46:43 -0000
*************** Wbad-function-cast
*** 128,133 ****
--- 128,138 ----
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: doc/invoke.texi
===================================================================
RCS file: /cvs/gcc/gcc/gcc/doc/invoke.texi,v
retrieving revision 1.632
diff -p -r1.632 invoke.texi
*** doc/invoke.texi 6 Jun 2005 02:32:27 -0000 1.632
--- doc/invoke.texi 9 Jun 2005 17:46:54 -0000
*************** Objective-C and Objective-C++ Dialects}.
*** 219,225 ****
@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
-Wconversion -Wno-deprecated-declarations @gol
-Wdisabled-optimization -Wno-div-by-zero -Wno-endif-labels @gol
-Werror -Werror-implicit-function-declaration @gol
--- 219,225 ----
@xref{Warning Options,,Options to Request or Suppress Warnings}.
@gccoptlist{-fsyntax-only -pedantic -pedantic-errors @gol
-w -Wextra -Wall -Waggregate-return -Wno-attributes @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
*************** to functions.
*** 2993,2998 ****
--- 2993,3003 ----
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: testsuite/gcc.dg/Wcxx-compat-1.c
===================================================================
RCS file: testsuite/gcc.dg/Wcxx-compat-1.c
diff -N testsuite/gcc.dg/Wcxx-compat-1.c
*** /dev/null 1 Jan 1970 00:00:00 -0000
--- testsuite/gcc.dg/Wcxx-compat-1.c 9 Jun 2005 17:47:11 -0000
***************
*** 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;
+ }