diff options
author | Mark Mitchell <mark@markmitchell.com> | 1998-06-13 23:45:18 +0000 |
---|---|---|
committer | Mark Mitchell <mmitchel@gcc.gnu.org> | 1998-06-13 23:45:18 +0000 |
commit | 8f259df3c054e887bf95c598842a4245195a1107 (patch) | |
tree | 6c025d8e59042c495188e1596d323a743397764a /gcc | |
parent | 581d38d0bac90445b1a58cff2857609d141e995f (diff) | |
download | gcc-8f259df3c054e887bf95c598842a4245195a1107.zip gcc-8f259df3c054e887bf95c598842a4245195a1107.tar.gz gcc-8f259df3c054e887bf95c598842a4245195a1107.tar.bz2 |
cp-tree.h (complete_type_or_else): Declare.
* cp-tree.h (complete_type_or_else): Declare.
* init.c (build_new_1, build_delete): Use it.
* typeck.c (require_complete_type): Use complete_type, rather than
expanding it inline.
(complete_type_or_else): New function.
(build_component_ref): Use it.
(pointer_int_sum): Make sure the type pointed to is complete.
(pointer_diff): Likewise.
From-SVN: r20499
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/cp/ChangeLog | 17 | ||||
-rw-r--r-- | gcc/cp/cp-tree.h | 2 | ||||
-rw-r--r-- | gcc/cp/init.c | 14 | ||||
-rw-r--r-- | gcc/cp/typeck.c | 48 | ||||
-rw-r--r-- | gcc/testsuite/g++.old-deja/g++.pt/pointer1.C | 17 |
5 files changed, 76 insertions, 22 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index ee9d746..1ad9098 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,20 @@ +1998-06-13 Mark Mitchell <mark@markmitchell.com> + + * cp-tree.h (complete_type_or_else): Declare. + * init.c (build_new_1, build_delete): Use it. + * typeck.c (require_complete_type): Use complete_type, rather than + expanding it inline. + (complete_type_or_else): New function. + (build_component_ref): Use it. + (pointer_int_sum): Make sure the type pointed to is complete. + (pointer_diff): Likewise. + + * pt.c (for_each_template_parm): Traverse the TYPE_CONTEXT for + types. + + * search.c (get_matching_virtual): Note that member templates + cannot override virtual functions. + 1998-06-12 Brendan Kehoe <brendan@cygnus.com> * pt.c (check_explicit_specialization): If DECLARATOR turned into diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index f0e59fd..2c2bb74 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -1738,6 +1738,7 @@ extern tree shorten_compare PROTO((tree *, tree *, tree *, e extern tree truthvalue_conversion PROTO((tree)); extern tree type_for_mode PROTO((enum machine_mode, int)); extern tree type_for_size PROTO((unsigned, int)); +extern int c_get_alias_set PROTO((tree)); /* in decl{2}.c */ extern tree void_list_node; @@ -2890,6 +2891,7 @@ extern tree condition_conversion PROTO((tree)); extern tree target_type PROTO((tree)); extern tree require_complete_type PROTO((tree)); extern tree complete_type PROTO((tree)); +extern tree complete_type_or_else PROTO((tree)); extern int type_unknown_p PROTO((tree)); extern int fntype_p PROTO((tree)); extern tree require_instantiated_type PROTO((tree, tree, tree)); diff --git a/gcc/cp/init.c b/gcc/cp/init.c index cf6378b..aa8fb0c 100644 --- a/gcc/cp/init.c +++ b/gcc/cp/init.c @@ -2192,11 +2192,8 @@ build_new_1 (exp) true_type = TREE_TYPE (true_type); } - if (TYPE_SIZE (complete_type (true_type)) == 0) - { - incomplete_type_error (0, true_type); - return error_mark_node; - } + if (!complete_type_or_else (true_type)) + return error_mark_node; if (has_array) size = fold (build_binary_op (MULT_EXPR, size_in_bytes (true_type), @@ -2971,11 +2968,8 @@ build_delete (type, addr, auto_delete, flags, use_global_delete) if (TREE_CODE (type) == POINTER_TYPE) { type = TYPE_MAIN_VARIANT (TREE_TYPE (type)); - if (TYPE_SIZE (complete_type (type)) == 0) - { - incomplete_type_error (0, type); - return error_mark_node; - } + if (!complete_type_or_else (type)) + return error_mark_node; if (TREE_CODE (type) == ARRAY_TYPE) goto handle_array; if (! IS_AGGR_TYPE (type)) diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index 4b2e587..b8a46d1 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -120,17 +120,20 @@ require_complete_type (value) return require_complete_type (value); } - if (IS_AGGR_TYPE (type) && CLASSTYPE_TEMPLATE_INSTANTIATION (type)) + if (TYPE_SIZE (complete_type (type))) + return value; + else { - instantiate_class_template (TYPE_MAIN_VARIANT (type)); - if (TYPE_SIZE (type) != 0) - return value; + incomplete_type_error (value, type); + return error_mark_node; } - - incomplete_type_error (value, type); - return error_mark_node; } +/* Try to complete TYPE, if it is incomplete. For example, if TYPE is + a template instantiation, do the instantiation. Returns TYPE, + whether or not it could be completed, unless something goes + horribly wrong, in which case the error_mark_node is returned. */ + tree complete_type (type) tree type; @@ -158,6 +161,24 @@ complete_type (type) return type; } +/* Like complete_type, but issue an error if the TYPE cannot be + completed. Returns NULL_TREE if the type cannot be made + complete. */ + +tree +complete_type_or_else (type) + tree type; +{ + type = complete_type (type); + if (type != error_mark_node && !TYPE_SIZE (type)) + { + incomplete_type_error (NULL_TREE, type); + return NULL_TREE; + } + else + return type; +} + /* Return truthvalue of whether type of EXP is instantiated. */ int @@ -1930,11 +1951,8 @@ build_component_ref (datum, component, basetype_path, protect) return error_mark_node; } - if (TYPE_SIZE (complete_type (basetype)) == 0) - { - incomplete_type_error (0, basetype); - return error_mark_node; - } + if (!complete_type_or_else (basetype)) + return error_mark_node; if (TREE_CODE (component) == BIT_NOT_EXPR) { @@ -3964,6 +3982,9 @@ pointer_int_sum (resultcode, ptrop, intop) register tree result_type = TREE_TYPE (ptrop); + if (!complete_type_or_else (result_type)) + return error_mark_node; + if (TREE_CODE (TREE_TYPE (result_type)) == VOID_TYPE) { if (pedantic || warn_pointer_arith) @@ -4053,6 +4074,9 @@ pointer_diff (op0, op1, ptrtype) tree restype = ptrdiff_type_node; tree target_type = TREE_TYPE (ptrtype); + if (!complete_type_or_else (target_type)) + return error_mark_node; + if (pedantic || warn_pointer_arith) { if (TREE_CODE (target_type) == VOID_TYPE) diff --git a/gcc/testsuite/g++.old-deja/g++.pt/pointer1.C b/gcc/testsuite/g++.old-deja/g++.pt/pointer1.C new file mode 100644 index 0000000..f854976 --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.pt/pointer1.C @@ -0,0 +1,17 @@ +// Build don't link: + +template <class T> +struct S1 +{ +}; + +template <class T> +struct S2 +{ + typedef T* pointer_t; +}; + +int f(S2<S1<int> >::pointer_t p1, S2<S1<int> >::pointer_t p2) +{ + return (int) (p1 - p2); +} |