re PR c++/5089 (-Wold-style-cast warns about cast to void)
PR c++/5089 * doc/invoke.texi (-Wold-style-cast): Only warn about non-void casts. cp: PR c++/5089 * decl2.c (reparse_absdcl_as_casts): Don't warn about casts to void. testsuite: * g++.dg/warn/oldcast1.C: New test. From-SVN: r48472
This commit is contained in:
parent
46c895ac0b
commit
323728aa26
@ -1,3 +1,8 @@
|
||||
2002-01-02 Nathan Sidwell <nathan@codesourcery.com>
|
||||
|
||||
PR c++/5089
|
||||
* doc/invoke.texi (-Wold-style-cast): Only warn about non-void casts.
|
||||
|
||||
2002-01-02 Kazu Hirata <kazu@hxi.com>
|
||||
|
||||
* config/h8300/fixunssfsi.c: Update copyright.
|
||||
|
@ -1,3 +1,8 @@
|
||||
2002-01-02 Nathan Sidwell <nathan@codesourcery.com>
|
||||
|
||||
PR c++/5089
|
||||
* decl2.c (reparse_absdcl_as_casts): Don't warn about casts to void.
|
||||
|
||||
2002-01-02 Nathan Sidwell <nathan@codesourcery.com>
|
||||
|
||||
PR c++/3716
|
||||
|
@ -3615,6 +3615,7 @@ reparse_absdcl_as_casts (decl, expr)
|
||||
tree decl, expr;
|
||||
{
|
||||
tree type;
|
||||
int non_void_p = 0;
|
||||
|
||||
if (TREE_CODE (expr) == CONSTRUCTOR
|
||||
&& TREE_TYPE (expr) == 0)
|
||||
@ -3639,11 +3640,13 @@ reparse_absdcl_as_casts (decl, expr)
|
||||
{
|
||||
type = groktypename (TREE_VALUE (CALL_DECLARATOR_PARMS (decl)));
|
||||
decl = TREE_OPERAND (decl, 0);
|
||||
if (!VOID_TYPE_P (type))
|
||||
non_void_p = 1;
|
||||
expr = build_c_cast (type, expr);
|
||||
}
|
||||
|
||||
if (warn_old_style_cast && ! in_system_header
|
||||
&& current_lang_name != lang_name_c)
|
||||
&& non_void_p && current_lang_name != lang_name_c)
|
||||
warning ("use of old-style cast");
|
||||
|
||||
return expr;
|
||||
|
@ -1557,10 +1557,10 @@ but disables the helpful warning.
|
||||
|
||||
@item -Wold-style-cast @r{(C++ only)}
|
||||
@opindex Wold-style-cast
|
||||
Warn if an old-style (C-style) cast is used within a C++ program. The
|
||||
new-style casts (@samp{static_cast}, @samp{reinterpret_cast}, and
|
||||
@samp{const_cast}) are less vulnerable to unintended effects, and much
|
||||
easier to grep for.
|
||||
Warn if an old-style (C-style) cast to a non-void type is used within
|
||||
a C++ program. The new-style casts (@samp{static_cast},
|
||||
@samp{reinterpret_cast}, and @samp{const_cast}) are less vulnerable to
|
||||
unintended effects, and much easier to grep for.
|
||||
|
||||
@item -Woverloaded-virtual @r{(C++ only)}
|
||||
@opindex Woverloaded-virtual
|
||||
|
@ -1,5 +1,7 @@
|
||||
2002-01-02 Nathan Sidwell <nathan@codesourcery.com>
|
||||
|
||||
* g++.dg/warn/oldcast1.C: New test.
|
||||
|
||||
* g++.dg/template/ptrmem1.C: New test.
|
||||
* g++.dg/template/ptrmem2.C: New test.
|
||||
|
||||
|
16
gcc/testsuite/g++.dg/warn/oldcast1.C
Normal file
16
gcc/testsuite/g++.dg/warn/oldcast1.C
Normal file
@ -0,0 +1,16 @@
|
||||
// { dg-do compile }
|
||||
// { dg-options "-ansi -pedantic-errors -Wold-style-cast" }
|
||||
|
||||
// Copyright (C) 2001 Free Software Foundation, Inc.
|
||||
// Contributed by Nathan Sidwell 26 Dec 2001 <nathan@codesourcery.com>
|
||||
|
||||
// PR 5089. old style cast to void should be permitted (think assert)
|
||||
|
||||
void foo ()
|
||||
{
|
||||
int i;
|
||||
float f = (float)i; // { dg-warning "use of old-style cast" "" }
|
||||
|
||||
(void)i;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user