From 0c4b14c4d320e7cbf65fe4d11b6c8a3e58d710d1 Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Mon, 29 Sep 1997 15:05:04 -0400 Subject: [PATCH] [multiple changes] Mon Sep 29 11:05:54 1997 Alexandre Oliva * lang-options.h: new -Wold-style-cast flag. * cp-tree.h (warn_old_style_cast): new variable. * decl2.c (warn_old_style_cast): ditto. (lang_decode_option): support -Wold-style-cast. (reparse_absdcl_as_casts): produce old-style-cast warning. Mon Sep 29 09:20:53 1997 Benjamin Kosnik * decl.c (cp_finish_decl): Allow expand_aggr_init to set TREE_USED, reset value based on already_used. * init.c (expand_member_init): Revert change. From-SVN: r15793 --- gcc/cp/ChangeLog | 15 +++++++++++++++ gcc/cp/cp-tree.h | 4 ++++ gcc/cp/decl.c | 7 +++++++ gcc/cp/decl2.c | 9 +++++++++ gcc/cp/lang-options.h | 2 ++ 5 files changed, 37 insertions(+) diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index e7da2dd201f..2fce4349bde 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,18 @@ +Mon Sep 29 11:05:54 1997 Alexandre Oliva + + * lang-options.h: new -Wold-style-cast flag. + * cp-tree.h (warn_old_style_cast): new variable. + * decl2.c (warn_old_style_cast): ditto. + (lang_decode_option): support -Wold-style-cast. + (reparse_absdcl_as_casts): produce old-style-cast warning. + +Mon Sep 29 09:20:53 1997 Benjamin Kosnik + + * decl.c (cp_finish_decl): Allow expand_aggr_init to set + TREE_USED, reset value based on already_used. + + * init.c (expand_member_init): Revert change. + Mon Sep 29 08:57:53 1997 Jason Merrill * cp-tree.h, decl.c, decl2.c, pt.c: diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index 8d1ccfc4fa6..9e04b698ba2 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -257,6 +257,10 @@ extern int warn_sign_promo; extern int warn_extern_inline; +/* Non-zero means warn when an old-style cast is used. */ + +extern int warn_old_style_cast; + /* Nonzero means to treat bitfields as unsigned unless they say `signed'. */ extern int flag_signed_bitfields; diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 40398185eba..695b1c4d39f 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -6299,6 +6299,7 @@ cp_finish_decl (decl, init, asmspec_tree, need_pop, flags) int temporary = allocation_temporary_p (); char *asmspec = NULL; int was_readonly = 0; + int already_used = 0; /* If this is 0, then we did not change obstacks. */ if (! decl) @@ -6858,6 +6859,7 @@ cp_finish_decl (decl, init, asmspec_tree, need_pop, flags) { /* Compute and store the initial value. */ expand_decl_init (decl); + already_used = TREE_USED (decl) || TREE_USED (type); if (init || TYPE_NEEDS_CONSTRUCTING (type)) { @@ -6870,10 +6872,15 @@ cp_finish_decl (decl, init, asmspec_tree, need_pop, flags) was initialized was ever used. Don't do this if it has a destructor, so we don't complain about the 'resource allocation is initialization' idiom. */ + if (TYPE_NEEDS_CONSTRUCTING (type) + && ! already_used && cleanup == NULL_TREE && DECL_NAME (decl)) TREE_USED (decl) = 0; + + if (already_used) + TREE_USED (decl) = 1; } /* Cleanup any temporaries needed for the initial value. */ diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c index 9125783b263..144502fb2b9 100644 --- a/gcc/cp/decl2.c +++ b/gcc/cp/decl2.c @@ -268,6 +268,10 @@ int warn_ecpp; int warn_sign_promo; +/* Nonzero means warn when an old-style cast is used. */ + +int warn_old_style_cast; + /* Nonzero means `$' can be in an identifier. See cccp.c for reasons why this breaks some obscure ANSI C programs. */ @@ -649,6 +653,8 @@ lang_decode_option (p) warn_ecpp = setting; else if (!strcmp (p, "sign-promo")) warn_sign_promo = setting; + else if (!strcmp (p, "old-style-cast")) + warn_old_style_cast = setting; else if (!strcmp (p, "comment")) ; /* cpp handles this one. */ else if (!strcmp (p, "comments")) @@ -3375,6 +3381,9 @@ reparse_absdcl_as_casts (decl, expr) expr = build_c_cast (type, expr); } + if (warn_old_style_cast) + warning ("use of old-style cast"); + return expr; } diff --git a/gcc/cp/lang-options.h b/gcc/cp/lang-options.h index 6679030ad34..045584965f8 100644 --- a/gcc/cp/lang-options.h +++ b/gcc/cp/lang-options.h @@ -111,3 +111,5 @@ Boston, MA 02111-1307, USA. */ "-Wno-effc++", "-Wsign-promo", "-Wno-sign-promo", + "-Wold-style-cast", + "-Wno-old-style-cast", -- 2.30.2