aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorNathan Sidwell <nathan@codesourcery.com>2002-01-02 13:59:10 +0000
committerNathan Sidwell <nathan@gcc.gnu.org>2002-01-02 13:59:10 +0000
commit323728aa2674aefa55a6ac912dce0a48388cc479 (patch)
treeb87648e849c6973022e42a9fe133b579e160eec2 /gcc
parent46c895ac0b9468a53f08e1875b13aca83227ec5d (diff)
downloadgcc-323728aa2674aefa55a6ac912dce0a48388cc479.zip
gcc-323728aa2674aefa55a6ac912dce0a48388cc479.tar.gz
gcc-323728aa2674aefa55a6ac912dce0a48388cc479.tar.bz2
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
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog5
-rw-r--r--gcc/cp/ChangeLog5
-rw-r--r--gcc/cp/decl2.c5
-rw-r--r--gcc/doc/invoke.texi8
-rw-r--r--gcc/testsuite/ChangeLog2
-rw-r--r--gcc/testsuite/g++.dg/warn/oldcast1.C16
6 files changed, 36 insertions, 5 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 36b9f99..b0b2741 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -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.
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index c259242..e74dc15 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -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.
diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c
index 3ff1ccc..04f77c9 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 d42df33..4a6ed0c 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 cdd244e..7e2fa43 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -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
index 0000000..26c0a5c
--- /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 <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;
+}
+