diff options
author | Mark Mitchell <mmitchel@gcc.gnu.org> | 2001-11-20 05:09:34 +0000 |
---|---|---|
committer | Mark Mitchell <mmitchel@gcc.gnu.org> | 2001-11-20 05:09:34 +0000 |
commit | 78a40378a9f48026652466b824b68f0a949f39ee (patch) | |
tree | 2669e6486e7ce424050fd284519d6fa62f1413da /gcc | |
parent | 34f62c3635821b9a5501031de5e3af0ef93d4189 (diff) | |
download | gcc-78a40378a9f48026652466b824b68f0a949f39ee.zip gcc-78a40378a9f48026652466b824b68f0a949f39ee.tar.gz gcc-78a40378a9f48026652466b824b68f0a949f39ee.tar.bz2 |
re PR c++/4629 (non-constant `sizeof (void*)' cannot be used as template argument)
* dump.c (dump_op): New function.
(cp_dump_tree): Dump CLASSTYPE_TEMPLATE_SPECIALIZATION. Use
dump_op. Dump DECL_MUTABLE, access and staticness for VAR_DECLs.
DECL_PURE_VIRTUAL_P, DECL_VIRTUAL_P,
PR4629
* semantics.c (finish_sizeof): Make sure that expression created
while processing a template do not have a type.
(finish_alignof): Likewise.
* typeck.c (c_sizeof): Likewise.
(expr_sizeof): Likewise.
From-SVN: r47201
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/cp/ChangeLog | 16 | ||||
-rw-r--r-- | gcc/cp/dump.c | 184 | ||||
-rw-r--r-- | gcc/cp/semantics.c | 4 | ||||
-rw-r--r-- | gcc/cp/typeck.c | 4 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/sizeof1.C | 15 |
5 files changed, 217 insertions, 6 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 06691eb..df49519 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,19 @@ +2001-11-19 John Wilkinson <johnw@research.att.com> + + * dump.c (dump_op): New function. + (cp_dump_tree): Dump CLASSTYPE_TEMPLATE_SPECIALIZATION. Use + dump_op. Dump DECL_MUTABLE, access and staticness for VAR_DECLs. + DECL_PURE_VIRTUAL_P, DECL_VIRTUAL_P, + +2001-11-19 Mark Mitchell <mark@codesourcery.com> + + PR4629 + * semantics.c (finish_sizeof): Make sure that expression created + while processing a template do not have a type. + (finish_alignof): Likewise. + * typeck.c (c_sizeof): Likewise. + (expr_sizeof): Likewise. + 2001-11-18 Neil Booth <neil@daikokuya.demon.co.uk> * lex.c (cxx_finish): Call c_common_finish. diff --git a/gcc/cp/dump.c b/gcc/cp/dump.c index 17a6b30..dea990a 100644 --- a/gcc/cp/dump.c +++ b/gcc/cp/dump.c @@ -28,6 +28,9 @@ Boston, MA 02111-1307, USA. */ static void dump_access PARAMS ((dump_info_p, tree)); +static void dump_op + PARAMS ((dump_info_p, tree)); + /* Dump a representation of the accessibility information associated with T. */ @@ -44,6 +47,166 @@ dump_access (di, t) dump_string (di, "public"); } +/* Dump a representation of the specific operator for an overloaded + operator associated with node t. +*/ + +static void +dump_op (di, t) + dump_info_p di; + tree t; +{ + switch (DECL_OVERLOADED_OPERATOR_P (t)) { + case NEW_EXPR: + dump_string (di, "new"); + break; + case VEC_NEW_EXPR: + dump_string (di, "vecnew"); + break; + case DELETE_EXPR: + dump_string (di, "delete"); + break; + case VEC_DELETE_EXPR: + dump_string (di, "vecdelete"); + break; + case CONVERT_EXPR: + dump_string (di, "pos"); + break; + case NEGATE_EXPR: + dump_string (di, "neg"); + break; + case ADDR_EXPR: + dump_string (di, "addr"); + break; + case INDIRECT_REF: + dump_string(di, "deref"); + break; + case BIT_NOT_EXPR: + dump_string(di, "not"); + break; + case TRUTH_NOT_EXPR: + dump_string(di, "lnot"); + break; + case PREINCREMENT_EXPR: + dump_string(di, "preinc"); + break; + case PREDECREMENT_EXPR: + dump_string(di, "predec"); + break; + case PLUS_EXPR: + if (DECL_ASSIGNMENT_OPERATOR_P (t)) + dump_string (di, "plusassign"); + else + dump_string(di, "plus"); + break; + case MINUS_EXPR: + if (DECL_ASSIGNMENT_OPERATOR_P (t)) + dump_string (di, "minusassign"); + else + dump_string(di, "minus"); + break; + case MULT_EXPR: + if (DECL_ASSIGNMENT_OPERATOR_P (t)) + dump_string (di, "multassign"); + else + dump_string (di, "mult"); + break; + case TRUNC_DIV_EXPR: + if (DECL_ASSIGNMENT_OPERATOR_P (t)) + dump_string (di, "divassign"); + else + dump_string (di, "div"); + break; + case TRUNC_MOD_EXPR: + if (DECL_ASSIGNMENT_OPERATOR_P (t)) + dump_string (di, "modassign"); + else + dump_string (di, "mod"); + break; + case BIT_AND_EXPR: + if (DECL_ASSIGNMENT_OPERATOR_P (t)) + dump_string (di, "andassign"); + else + dump_string (di, "and"); + break; + case BIT_IOR_EXPR: + if (DECL_ASSIGNMENT_OPERATOR_P (t)) + dump_string (di, "orassign"); + else + dump_string (di, "or"); + break; + case BIT_XOR_EXPR: + if (DECL_ASSIGNMENT_OPERATOR_P (t)) + dump_string (di, "xorassign"); + else + dump_string (di, "xor"); + break; + case LSHIFT_EXPR: + if (DECL_ASSIGNMENT_OPERATOR_P (t)) + dump_string (di, "lshiftassign"); + else + dump_string (di, "lshift"); + break; + case RSHIFT_EXPR: + if (DECL_ASSIGNMENT_OPERATOR_P (t)) + dump_string (di, "rshiftassign"); + else + dump_string (di, "rshift"); + break; + case EQ_EXPR: + dump_string (di, "eq"); + break; + case NE_EXPR: + dump_string (di, "ne"); + break; + case LT_EXPR: + dump_string (di, "lt"); + break; + case GT_EXPR: + dump_string (di, "gt"); + break; + case LE_EXPR: + dump_string (di, "le"); + break; + case GE_EXPR: + dump_string (di, "ge"); + break; + case TRUTH_ANDIF_EXPR: + dump_string (di, "land"); + break; + case TRUTH_ORIF_EXPR: + dump_string (di, "lor"); + break; + case COMPOUND_EXPR: + dump_string (di, "compound"); + break; + case MEMBER_REF: + dump_string (di, "memref"); + break; + case COMPONENT_REF: + dump_string (di, "ref"); + break; + case ARRAY_REF: + dump_string (di, "subs"); + break; + case POSTINCREMENT_EXPR: + dump_string (di, "postinc"); + break; + case POSTDECREMENT_EXPR: + dump_string (di, "postdec"); + break; + case CALL_EXPR: + dump_string (di, "call"); + break; + case NOP_EXPR: + if (DECL_ASSIGNMENT_OPERATOR_P (t)) + dump_string (di, "assign"); + break; + default: + break; + } +} + int cp_dump_tree (di, t) dump_info_p di; @@ -101,6 +264,8 @@ cp_dump_tree (di, t) } dump_child ("vfld", TYPE_VFIELD (t)); + if (CLASSTYPE_TEMPLATE_SPECIALIZATION(t)) + dump_string(di, "spec"); if (!dump_flag (di, TDF_SLIM, t)) { @@ -119,22 +284,37 @@ cp_dump_tree (di, t) case FIELD_DECL: dump_access (di, t); + if (DECL_MUTABLE_P (t)) + dump_string(di, "mutable"); break; + case VAR_DECL: + if (TREE_CODE (CP_DECL_CONTEXT (t)) == RECORD_TYPE) + dump_access (di, t); + if (TREE_STATIC (t) && !TREE_PUBLIC (t)) + dump_string (di, "static"); + break; + case FUNCTION_DECL: if (!DECL_THUNK_P (t)) { + if (DECL_OVERLOADED_OPERATOR_P (t)) { + dump_string (di, "operator"); + dump_op (di, t); + } if (DECL_FUNCTION_MEMBER_P (t)) { dump_string (di, "member"); dump_access (di, t); } + if (DECL_PURE_VIRTUAL_P (t)) + dump_string (di, "pure"); + if (DECL_VIRTUAL_P (t)) + dump_string (di, "virtual"); if (DECL_CONSTRUCTOR_P (t)) dump_string (di, "constructor"); if (DECL_DESTRUCTOR_P (t)) dump_string (di, "destructor"); - if (DECL_OVERLOADED_OPERATOR_P (t)) - dump_string (di, "operator"); if (DECL_CONV_FN_P (t)) dump_string (di, "conversion"); if (DECL_GLOBAL_CTOR_P (t) || DECL_GLOBAL_DTOR_P (t)) diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index 1842974..ae1e597 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -2196,7 +2196,7 @@ finish_sizeof (t) tree t; { if (processing_template_decl) - return build_min (SIZEOF_EXPR, sizetype, t); + return build_min_nt (SIZEOF_EXPR, t); return TYPE_P (t) ? c_sizeof (t) : expr_sizeof (t); } @@ -2209,7 +2209,7 @@ finish_alignof (t) tree t; { if (processing_template_decl) - return build_min (ALIGNOF_EXPR, sizetype, t); + return build_min_nt (ALIGNOF_EXPR, t); return TYPE_P (t) ? c_alignof (t) : c_alignof_expr (t); } diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index 85dc1d3..e57dd1c 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -1552,7 +1552,7 @@ c_sizeof (type) tree size; if (processing_template_decl) - return build_min (SIZEOF_EXPR, sizetype, type); + return build_min_nt (SIZEOF_EXPR, type); if (code == FUNCTION_TYPE) { @@ -1614,7 +1614,7 @@ expr_sizeof (e) tree e; { if (processing_template_decl) - return build_min (SIZEOF_EXPR, sizetype, e); + return build_min_nt (SIZEOF_EXPR, e); if (TREE_CODE (e) == COMPONENT_REF && DECL_C_BIT_FIELD (TREE_OPERAND (e, 1))) diff --git a/gcc/testsuite/g++.dg/sizeof1.C b/gcc/testsuite/g++.dg/sizeof1.C new file mode 100644 index 0000000..328d647 --- /dev/null +++ b/gcc/testsuite/g++.dg/sizeof1.C @@ -0,0 +1,15 @@ +// Test use of `sizeof' as a template parameter. +// Origin: smacdonald@seimac.com + +// { dg-do compile } + +template <unsigned I> struct A {}; + +template <typename SizeType> +struct B +{ +char * f() const +{ +return (A<sizeof(void *)>::value); +} +}; |