OSDN Git Service

* pt.c (convert_nontype_argument): Issue an error when presented
authormmitchel <mmitchel@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 17 Jun 1998 21:52:30 +0000 (21:52 +0000)
committermmitchel <mmitchel@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 17 Jun 1998 21:52:30 +0000 (21:52 +0000)
with an integer (real) constant that cannot be simplified to an
INT_CST (REAL_CST).

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@20550 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/cp/ChangeLog
gcc/cp/pt.c
gcc/testsuite/g++.old-deja/g++.pt/crash10.C [new file with mode: 0644]

index 284c9c0..5af8932 100644 (file)
@@ -1,5 +1,9 @@
 1998-06-17  Mark Mitchell  <mark@markmitchell.com>
 
+       * pt.c (convert_nontype_argument): Issue an error when presented
+       with an integer (real) constant that cannot be simplified to an
+       INT_CST (REAL_CST).
+
        * cp-tree.h (c_get_alias_set): Remove declaration added in
        1998-06-13 change that should never have been checked in.
 
index 9fe7fdd..3b883b8 100644 (file)
@@ -2056,6 +2056,7 @@ convert_nontype_argument (type, expr)
     {
       if (! TREE_CONSTANT (expr))
        {
+       non_constant:
          cp_error ("non-constant `%E' cannot be used as template argument",
                    expr);
          return NULL_TREE;
@@ -2128,15 +2129,28 @@ convert_nontype_argument (type, expr)
       
       /* It's safe to call digest_init in this case; we know we're
         just converting one integral constant expression to another.  */
-      return digest_init (type, expr, (tree*) 0);
+      expr = digest_init (type, expr, (tree*) 0);
 
+      if (TREE_CODE (expr) != INTEGER_CST)
+       /* Curiously, some TREE_CONSTNAT integral expressions do not
+          simplify to integer constants.  For example, `3 % 0',
+          remains a TRUNC_MOD_EXPR.  */
+       goto non_constant;
+      
+      return expr;
+       
     case REAL_TYPE:
     case COMPLEX_TYPE:
       /* These are g++ extensions.  */
       if (TREE_CODE (expr_type) != TREE_CODE (type))
        return error_mark_node;
 
-      return digest_init (type, expr, (tree*) 0);
+      expr = digest_init (type, expr, (tree*) 0);
+      
+      if (TREE_CODE (expr) != REAL_CST)
+       goto non_constant;
+
+      return expr;
 
     case POINTER_TYPE:
       {
diff --git a/gcc/testsuite/g++.old-deja/g++.pt/crash10.C b/gcc/testsuite/g++.old-deja/g++.pt/crash10.C
new file mode 100644 (file)
index 0000000..974cafc
--- /dev/null
@@ -0,0 +1,11 @@
+// Build don't link:
+
+template<int M, int N>
+class GCD {
+public:
+  enum { val = (N == 0) ? M : GCD<N, M % N>::val }; 
+};
+
+main() {
+  GCD< 1, 0 >::val; // ERROR - division
+}