diff options
author | Mark Mitchell <mark@codesourcery.com> | 2005-12-20 08:48:13 +0000 |
---|---|---|
committer | Mark Mitchell <mmitchel@gcc.gnu.org> | 2005-12-20 08:48:13 +0000 |
commit | 68d04c6749ba2b4e912e359da1706fe6617116c8 (patch) | |
tree | be663b0ecc3d9eb125f8cd7f7af5c682c5c9353e | |
parent | c3115fd2d9b8c820af8900b35e3aec3857a3c888 (diff) | |
download | gcc-68d04c6749ba2b4e912e359da1706fe6617116c8.zip gcc-68d04c6749ba2b4e912e359da1706fe6617116c8.tar.gz gcc-68d04c6749ba2b4e912e359da1706fe6617116c8.tar.bz2 |
re PR c++/21228 (-Wunreachable-code produces spurious warnings for constructor)
PR c++/21228
* decl.c (use_eh_spec_block): New function.
(store_parm_decls): Use it.
(finish_function): Likewise.
PR c++/21228
* g++.dg/warn/Wunreachable-code-2.C: New test.
From-SVN: r108851
-rw-r--r-- | gcc/cp/ChangeLog | 7 | ||||
-rw-r--r-- | gcc/cp/decl.c | 41 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/warn/Wunreachable-code-2.C | 23 |
4 files changed, 62 insertions, 14 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 2b3c175..766fbd5 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,10 @@ +2005-12-20 Mark Mitchell <mark@codesourcery.com> + + PR c++/21228 + * decl.c (use_eh_spec_block): New function. + (store_parm_decls): Use it. + (finish_function): Likewise. + 2005-12-19 Mark Mitchell <mark@codesourcery.com> PR c++/24278 diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index ffa5e33..447e98d 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -10482,6 +10482,30 @@ start_function (cp_decl_specifier_seq *declspecs, return 1; } +/* Returns true iff an EH_SPEC_BLOCK should be created in the body of + FN. */ + +static bool +use_eh_spec_block (tree fn) +{ + return (flag_exceptions && flag_enforce_eh_specs + && !processing_template_decl + && TYPE_RAISES_EXCEPTIONS (TREE_TYPE (fn)) + /* We insert the EH_SPEC_BLOCK only in the original + function; then, it is copied automatically to the + clones. */ + && !DECL_CLONED_FUNCTION_P (fn) + /* Implicitly-generated constructors and destructors have + exception specifications. However, those specifications + are the union of the possible exceptions specified by the + constructors/destructors for bases and members, so no + unallowed exception will ever reach this function. By + not creating the EH_SPEC_BLOCK we save a little memory, + and we avoid spurious warnings about unreachable + code. */ + && !DECL_ARTIFICIAL (fn)); +} + /* Store the parameter declarations into the current function declaration. This is called after parsing the parameter declarations, before digesting the body of the function. @@ -10552,16 +10576,8 @@ store_parm_decls (tree current_function_parms) DECL_ARGUMENTS is not modified. */ current_binding_level->names = chainon (nonparms, DECL_ARGUMENTS (fndecl)); - /* For a cloned function, we've already got all the code we need; - there's no need to add any extra bits. */ - if (!DECL_CLONED_FUNCTION_P (fndecl)) - { - /* Do the starting of the exception specifications, if we have any. */ - if (flag_exceptions && !processing_template_decl - && flag_enforce_eh_specs - && TYPE_RAISES_EXCEPTIONS (TREE_TYPE (current_function_decl))) - current_eh_spec_block = begin_eh_spec_block (); - } + if (use_eh_spec_block (current_function_decl)) + current_eh_spec_block = begin_eh_spec_block (); } @@ -10848,10 +10864,7 @@ finish_function (int flags) #endif } - /* Finish dealing with exception specifiers. */ - if (flag_exceptions && !processing_template_decl - && flag_enforce_eh_specs - && TYPE_RAISES_EXCEPTIONS (TREE_TYPE (current_function_decl))) + if (use_eh_spec_block (current_function_decl)) finish_eh_spec_block (TYPE_RAISES_EXCEPTIONS (TREE_TYPE (current_function_decl)), current_eh_spec_block); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index fe6953e..7073aec 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2005-12-20 Mark Mitchell <mark@codesourcery.com> + + PR c++/21228 + * g++.dg/warn/Wunreachable-code-2.C: New test. + 2005-12-19 Mark Mitchell <mark@codesourcery.com> PR c++/24278 diff --git a/gcc/testsuite/g++.dg/warn/Wunreachable-code-2.C b/gcc/testsuite/g++.dg/warn/Wunreachable-code-2.C new file mode 100644 index 0000000..d50f7fe --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wunreachable-code-2.C @@ -0,0 +1,23 @@ +// PR c++/21228 +/* { dg-options "-Wunreachable-code" } */ + +class testStringBase +{ +public: + char *stringPtr; +}; + +class testString : public testStringBase +{ +public: + testString(); +}; + +testString::testString() +{ + stringPtr = (char *) 9; +} + +int main(int argc, char **argv) { + testString s; +} |