diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index f654b18f735a171fcb42d924701eb33e53a0eb23..59402a0aa1ff3539c137fe3faea9d205f5c51bb1 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,9 @@
+2004-04-23  Giovanni Bajo  <giovannibajo@gcc.gnu.org>
+
+	PR c++/15064
+	* parser.c (cp_parser_postfix_expression): typeid operator cannot be
+	used in integral constant expressions.
+
 2004-04-22  Mark Mitchell  <mark@codesourcery.com>
 
 	* init.c (build_aggr_init): Fix accidental use of C99 construct in
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 0732a650452d0617fc7a457d0c6bfb1e56a9c242..6fb8da5d158c07a09a02063a54b57d112d9b64cb 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -3594,7 +3594,10 @@ cp_parser_postfix_expression (cp_parser *parser, bool address_p)
 	    /* Look for the `)' token.  */
 	    cp_parser_require (parser, CPP_CLOSE_PAREN, "`)'");
 	  }
-
+	/* `typeid' may not appear in an integral constant expression.  */
+	if (cp_parser_non_integral_constant_expression(parser, 
+						       "`typeid' operator"))
+	  return error_mark_node;
 	/* Restore the saved message.  */
 	parser->type_definition_forbidden_message = saved_message;
       }
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index aa479b4aa23707f152e7e32966c56f51652d613f..b57694e76f40101f8bed5930414482102a950d8f 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2004-04-23  Giovanni Bajo  <giovannibajo@gcc.gnu.org>
+
+	PR c++/15064
+	* g++.dg/template/crash18.C: New test.
+
 2004-04-22  Mark Mitchell  <mark@codesourcery.com>
 
 	* g++.dg/ext/complit3.C: New test.
diff --git a/gcc/testsuite/g++.dg/template/crash18.C b/gcc/testsuite/g++.dg/template/crash18.C
new file mode 100644
index 0000000000000000000000000000000000000000..5eb92929cbdf3955a9fa820ce00144c9594fd53b
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/crash18.C
@@ -0,0 +1,13 @@
+// { dg-do compile }
+// Contributed by: <leif dot lonnblad at thep dot lu dot se>
+// PR c++/15064: typeid does not form an integral constant expression
+
+#include <typeinfo>
+
+template <typename T>
+void dummy() {
+  const std::type_info& t = typeid(T);
+  const std::type_info& t2 = typeid(float);
+}
+
+template void dummy<int>(void);