diff options
| author | mmitchel <mmitchel@138bc75d-0d04-0410-961f-82ee72b054a4> | 1998-06-17 21:52:30 +0000 |
|---|---|---|
| committer | mmitchel <mmitchel@138bc75d-0d04-0410-961f-82ee72b054a4> | 1998-06-17 21:52:30 +0000 |
| commit | eb402de42d67cf7e767112eab9fe809aeaf871b5 (patch) | |
| tree | 20fbd7173e8a047ea6ba6cfa19b237f5340e0dbb /gcc | |
| parent | b27468f3b323cd48d80413e0c1c4f2c406490e8f (diff) | |
| download | ppe42-gcc-eb402de42d67cf7e767112eab9fe809aeaf871b5.tar.gz ppe42-gcc-eb402de42d67cf7e767112eab9fe809aeaf871b5.zip | |
* 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).
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@20550 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc')
| -rw-r--r-- | gcc/cp/ChangeLog | 4 | ||||
| -rw-r--r-- | gcc/cp/pt.c | 18 | ||||
| -rw-r--r-- | gcc/testsuite/g++.old-deja/g++.pt/crash10.C | 11 |
3 files changed, 31 insertions, 2 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 284c9c082c5..5af8932281e 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 9fe7fdd6ccb..3b883b8c06b 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 00000000000..974cafc8731 --- /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 +} |

