re PR c++/4629 (non-constant `sizeof (void*)' cannot be used as template argument)
authorMark Mitchell <mmitchel@gcc.gnu.org>
Tue, 20 Nov 2001 05:09:34 +0000 (05:09 +0000)
committerMark Mitchell <mmitchel@gcc.gnu.org>
Tue, 20 Nov 2001 05:09:34 +0000 (05:09 +0000)
* 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

gcc/cp/ChangeLog
gcc/cp/dump.c
gcc/cp/semantics.c
gcc/cp/typeck.c
gcc/testsuite/g++.dg/sizeof1.C [new file with mode: 0644]

index 06691eb681e1c7865116e8f408c0d0f4e43695c2..df495199dadd54a3fb50912b557a0d4957b37baf 100644 (file)
@@ -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.
index 17a6b30b7058cd472a599f2914b409b6d5eaeec2..dea990aa4c2256795a14b7b19a165da775afd9cb 100644 (file)
@@ -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))
index 1842974263afdd6bd6659d4e9614b487c0409cb9..ae1e59758188a97ed2a38bcb1a907fc2371fced8 100644 (file)
@@ -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);
 }
index 85dc1d38e14ed1fe188f759b31ab8adc4a569658..e57dd1cc18d77cb0368e374763554c2010ead673 100644 (file)
@@ -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 (file)
index 0000000..328d647
--- /dev/null
@@ -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);
+}
+};