aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorMark Mitchell <mark@markmitchell.com>1998-06-17 21:52:30 +0000
committerMark Mitchell <mmitchel@gcc.gnu.org>1998-06-17 21:52:30 +0000
commitdb02b6b9b03846caee837a44941a38149a2e12d2 (patch)
tree20fbd7173e8a047ea6ba6cfa19b237f5340e0dbb /gcc
parent8fa8d8c5c7ce5d6c95bafee8314319a94775904f (diff)
downloadgcc-db02b6b9b03846caee837a44941a38149a2e12d2.zip
gcc-db02b6b9b03846caee837a44941a38149a2e12d2.tar.gz
gcc-db02b6b9b03846caee837a44941a38149a2e12d2.tar.bz2
pt.c (convert_nontype_argument): Issue an error when presented with an integer (real) constant that cannot be...
* 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). From-SVN: r20550
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/ChangeLog4
-rw-r--r--gcc/cp/pt.c18
-rw-r--r--gcc/testsuite/g++.old-deja/g++.pt/crash10.C11
3 files changed, 31 insertions, 2 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 284c9c0..5af8932 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -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.
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 9fe7fdd..3b883b8 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -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
index 0000000..974cafc
--- /dev/null
+++ b/gcc/testsuite/g++.old-deja/g++.pt/crash10.C
@@ -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
+}