diff options
author | Mark Mitchell <mark@codesourcery.com> | 2002-10-04 05:13:59 +0000 |
---|---|---|
committer | Mark Mitchell <mmitchel@gcc.gnu.org> | 2002-10-04 05:13:59 +0000 |
commit | bd9bb3d2b01e5f69a42118114baddf16e1862101 (patch) | |
tree | 48ff2f7f2c9fc83ca936cfb7cd280a4c8cd24e18 /gcc | |
parent | 6397d80b752df0770438e1edbc1efd8773fbb7eb (diff) | |
download | gcc-bd9bb3d2b01e5f69a42118114baddf16e1862101.zip gcc-bd9bb3d2b01e5f69a42118114baddf16e1862101.tar.gz gcc-bd9bb3d2b01e5f69a42118114baddf16e1862101.tar.bz2 |
re PR c++/7931 (The compiler ices on some legal code)
PR c++/7931
* pt.c (for_each_template_parm_r): Handle BASELINKs.
PR c++/7754
* decl2.c (finish_anon_union): Do not expand anonymous unions when
procesing template functions.
* pt.c (tsubst_decl, case VAR_DECL): Try to complete the variable
type. Call layout_decl.
(tsubst_expr, case DECL_STMT): Handle anonymous unions.
PR c++/7931
* g++.dg/template/ptrmem3.C: New test.
PR c++/7754
* g++.dg/template/union1.C: New test.
From-SVN: r57800
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/cp/ChangeLog | 12 | ||||
-rw-r--r-- | gcc/cp/decl2.c | 39 | ||||
-rw-r--r-- | gcc/cp/pt.c | 45 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 8 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/template/ptrmem3.C | 22 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/template/union1.C | 29 |
6 files changed, 123 insertions, 32 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index f10a564..78ffd60f 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,17 @@ 2002-10-03 Mark Mitchell <mark@codesourcery.com> + PR c++/7931 + * pt.c (for_each_template_parm_r): Handle BASELINKs. + + PR c++/7754 + * decl2.c (finish_anon_union): Do not expand anonymous unions when + procesing template functions. + * pt.c (tsubst_decl, case VAR_DECL): Try to complete the variable + type. Call layout_decl. + (tsubst_expr, case DECL_STMT): Handle anonymous unions. + +2002-10-03 Mark Mitchell <mark@codesourcery.com> + PR c++/8006 * mangle.c (CLASSTYPE_TEMPLATE_ID_P): Handle instances of template template parameters. diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c index 90a4d4a..c738b37 100644 --- a/gcc/cp/decl2.c +++ b/gcc/cp/decl2.c @@ -1382,26 +1382,31 @@ finish_anon_union (anon_union_decl) return; } - main_decl = build_anon_union_vars (anon_union_decl, - &DECL_ANON_UNION_ELEMS (anon_union_decl), - static_p, external_p); - - if (main_decl == NULL_TREE) + if (!processing_template_decl) { - warning ("anonymous aggregate with no members"); - return; - } + main_decl + = build_anon_union_vars (anon_union_decl, + &DECL_ANON_UNION_ELEMS (anon_union_decl), + static_p, external_p); + + if (main_decl == NULL_TREE) + { + warning ("anonymous aggregate with no members"); + return; + } - if (static_p) - { - make_decl_rtl (main_decl, 0); - COPY_DECL_RTL (main_decl, anon_union_decl); - expand_anon_union_decl (anon_union_decl, - NULL_TREE, - DECL_ANON_UNION_ELEMS (anon_union_decl)); + if (static_p) + { + make_decl_rtl (main_decl, 0); + COPY_DECL_RTL (main_decl, anon_union_decl); + expand_anon_union_decl (anon_union_decl, + NULL_TREE, + DECL_ANON_UNION_ELEMS (anon_union_decl)); + return; + } } - else - add_decl_stmt (anon_union_decl); + + add_decl_stmt (anon_union_decl); } /* Finish processing a builtin type TYPE. It's name is NAME, diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 6d8ec06..242c528 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -4469,6 +4469,15 @@ for_each_template_parm_r (tp, walk_subtrees, d) return error_mark_node; break; + case BASELINK: + /* If we do not handle this case specially, we end up walking + the BINFO hierarchy, which is circular, and therefore + confuses walk_tree. */ + *walk_subtrees = 0; + if (for_each_template_parm (BASELINK_FUNCTIONS (*tp), fn, data)) + return error_mark_node; + break; + default: break; } @@ -6125,7 +6134,7 @@ tsubst_decl (t, args, type, complain) } r = copy_decl (t); - TREE_TYPE (r) = type; + TREE_TYPE (r) = complete_type (type); c_apply_type_quals_to_decl (cp_type_quals (type), r); DECL_CONTEXT (r) = ctx; /* Clear out the mangled name and RTL for the instantiation. */ @@ -6164,6 +6173,8 @@ tsubst_decl (t, args, type, complain) TREE_CHAIN (r) = NULL_TREE; if (TREE_CODE (r) == VAR_DECL && VOID_TYPE_P (type)) cp_error_at ("instantiation of `%D' as type `%T'", r, type); + /* Compute the size, alignment, etc. of R. */ + layout_decl (r, 0); } break; @@ -7415,9 +7426,6 @@ tsubst_expr (t, args, complain, in_decl) decl = tsubst (decl, args, complain, in_decl); if (decl != error_mark_node) { - if (TREE_CODE (decl) != TYPE_DECL) - /* Make sure the type is instantiated now. */ - complete_type (TREE_TYPE (decl)); if (init) DECL_INITIAL (decl) = error_mark_node; /* By marking the declaration as instantiated, we avoid @@ -7427,19 +7435,26 @@ tsubst_expr (t, args, complain, in_decl) do. */ if (TREE_CODE (decl) == VAR_DECL) DECL_TEMPLATE_INSTANTIATED (decl) = 1; - maybe_push_decl (decl); - if (DECL_PRETTY_FUNCTION_P (decl)) + if (TREE_CODE (decl) == VAR_DECL + && ANON_AGGR_TYPE_P (TREE_TYPE (decl))) + /* Anonymous aggregates are a special case. */ + finish_anon_union (decl); + else { - /* For __PRETTY_FUNCTION__ we have to adjust the - initializer. */ - const char *const name - = cxx_printable_name (current_function_decl, 2); - init = cp_fname_init (name); - TREE_TYPE (decl) = TREE_TYPE (init); + maybe_push_decl (decl); + if (DECL_PRETTY_FUNCTION_P (decl)) + { + /* For __PRETTY_FUNCTION__ we have to adjust the + initializer. */ + const char *const name + = cxx_printable_name (current_function_decl, 2); + init = cp_fname_init (name); + TREE_TYPE (decl) = TREE_TYPE (init); + } + else + init = tsubst_expr (init, args, complain, in_decl); + cp_finish_decl (decl, init, NULL_TREE, 0); } - else - init = tsubst_expr (init, args, complain, in_decl); - cp_finish_decl (decl, init, NULL_TREE, 0); } } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 6162206..5a66325 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,13 @@ 2002-10-03 Mark Mitchell <mark@codesourcery.com> + PR c++/7931 + * g++.dg/template/ptrmem3.C: New test. + + PR c++/7754 + * g++.dg/template/union1.C: New test. + +2002-10-03 Mark Mitchell <mark@codesourcery.com> + PR c++/8006 * g++.dg/abi/mangle9.C: New test. * g++.dg/abi/mangle10.C: New test. diff --git a/gcc/testsuite/g++.dg/template/ptrmem3.C b/gcc/testsuite/g++.dg/template/ptrmem3.C new file mode 100644 index 0000000..fda7bf1 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/ptrmem3.C @@ -0,0 +1,22 @@ +// Origin: Theo Papadopoulo <Theodore.Papadopoulo@sophia.inria.fr> + +template <typename T,double (T::*fun)() const> +struct I { +}; + +struct R { + R() { } +}; + +class H: public R { +public: + H(): R() { } + double& f() { return a; } + double f() const { return 1.0; } + double a; +}; + +struct A { + typedef I<H,&H::f> F; + A() { } +}; diff --git a/gcc/testsuite/g++.dg/template/union1.C b/gcc/testsuite/g++.dg/template/union1.C new file mode 100644 index 0000000..9019c38 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/union1.C @@ -0,0 +1,29 @@ +// { dg-do run } + +extern "C" void abort (); + +void g (char c) +{ + if (c != 'a') + abort (); +} + +void h (int i) +{ + if (i != 3) + abort (); +} + +template <typename T> void f(T const &t) +{ + union { char c; T t_; }; + + c = 'a'; + g (c); + t_ = 3; + h (t_); +} + +int main () { + f (3); +} |