Commit b7e20b53 by Gabriel Dos Reis Committed by Gabriel Dos Reis

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
parent 92f5e87c
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.
......
......@@ -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.
......
......@@ -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
......
......@@ -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
......
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
......
/* 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;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment