OSDN Git Service

PR c++/5089
authornathan <nathan@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 2 Jan 2002 13:59:10 +0000 (13:59 +0000)
committernathan <nathan@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 2 Jan 2002 13:59:10 +0000 (13:59 +0000)
* 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.

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

gcc/ChangeLog
gcc/cp/ChangeLog
gcc/cp/decl2.c
gcc/doc/invoke.texi
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/warn/oldcast1.C [new file with mode: 0644]

index 36b9f99..b0b2741 100644 (file)
@@ -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.
index c259242..e74dc15 100644 (file)
@@ -1,5 +1,10 @@
 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
        * pt.c (tsubst_aggr_type): Move pmf handling into tsubst.
        (tsubst, case POINTER_TYPE): Handle pmfs here.
index 3ff1ccc..04f77c9 100644 (file)
@@ -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;
index d42df33..4a6ed0c 100644 (file)
@@ -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
index cdd244e..7e2fa43 100644 (file)
@@ -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.
 
diff --git a/gcc/testsuite/g++.dg/warn/oldcast1.C b/gcc/testsuite/g++.dg/warn/oldcast1.C
new file mode 100644 (file)
index 0000000..26c0a5c
--- /dev/null
@@ -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;
+}
+