From 323728aa2674aefa55a6ac912dce0a48388cc479 Mon Sep 17 00:00:00 2001 From: Nathan Sidwell Date: Wed, 2 Jan 2002 13:59:10 +0000 Subject: [PATCH] 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 --- gcc/ChangeLog | 5 +++++ gcc/cp/ChangeLog | 5 +++++ gcc/cp/decl2.c | 5 ++++- gcc/doc/invoke.texi | 8 ++++---- gcc/testsuite/ChangeLog | 2 ++ gcc/testsuite/g++.dg/warn/oldcast1.C | 16 ++++++++++++++++ 6 files changed, 36 insertions(+), 5 deletions(-) create mode 100644 gcc/testsuite/g++.dg/warn/oldcast1.C diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 36b9f990cda..b0b274195fc 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2002-01-02 Nathan Sidwell + + PR c++/5089 + * doc/invoke.texi (-Wold-style-cast): Only warn about non-void casts. + 2002-01-02 Kazu Hirata * config/h8300/fixunssfsi.c: Update copyright. diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index c2592422934..e74dc1542c0 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2002-01-02 Nathan Sidwell + + PR c++/5089 + * decl2.c (reparse_absdcl_as_casts): Don't warn about casts to void. + 2002-01-02 Nathan Sidwell PR c++/3716 diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c index 3ff1ccc6228..04f77c9c00e 100644 --- a/gcc/cp/decl2.c +++ b/gcc/cp/decl2.c @@ -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; diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index d42df33f46e..4a6ed0c4aed 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -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 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index cdd244e48bc..7e2fa439c13 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,7 @@ 2002-01-02 Nathan Sidwell + * g++.dg/warn/oldcast1.C: New test. + * g++.dg/template/ptrmem1.C: New test. * g++.dg/template/ptrmem2.C: New test. diff --git a/gcc/testsuite/g++.dg/warn/oldcast1.C b/gcc/testsuite/g++.dg/warn/oldcast1.C new file mode 100644 index 00000000000..26c0a5c4d00 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/oldcast1.C @@ -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 + +// 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; +} + -- 2.30.2