diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index f48474cfe3ab792ab7b29469c9a281eac99e5b8d..eeec03d466fe4b8adb78b881771ac9eee626483d 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,9 @@
+2009-02-01  Paolo Carlini  <paolo.carlini@oracle.com>
+
+        PR c++/39053
+        * parser.c (cp_parser_pure_specifier): If there are no tokens left
+        do not call cp_lexer_consume_token.
+
 2009-01-30  Jakub Jelinek  <jakub@redhat.com>
 
 	PR c++/39028
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 5be23188155057492e45a333cb6c63b12312a57e..5675e9bca12a777c702ab63e3d38bfcbd1a43a48 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -15997,7 +15997,13 @@ cp_parser_pure_specifier (cp_parser* parser)
   if (!cp_parser_require (parser, CPP_EQ, "%<=%>"))
     return error_mark_node;
   /* Look for the `0' token.  */
-  token = cp_lexer_consume_token (parser->lexer);
+  token = cp_lexer_peek_token (parser->lexer);
+
+  if (token->type == CPP_EOF
+      || token->type == CPP_PRAGMA_EOL)
+    return error_mark_node;
+
+  cp_lexer_consume_token (parser->lexer);
 
   /* Accept = default or = delete in c++0x mode.  */
   if (token->keyword == RID_DEFAULT
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 02244e51b5dbd2d9be62a5dce62948aadf50e781..d5040061715f1516e544d51f917f0b0a74963829 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2009-02-01  Paolo Carlini  <paolo.carlini@oracle.com>
+
+        PR c++/39053
+        * g++.dg/parse/crash52.C: New.
+
 2009-01-30  Richard Guenther  <rguenther@suse.de>
 
 	PR tree-optimization/39041
diff --git a/gcc/testsuite/g++.dg/parse/crash52.C b/gcc/testsuite/g++.dg/parse/crash52.C
new file mode 100644
index 0000000000000000000000000000000000000000..bc7f03c8d972351ee2e00d42b33ee807901c7d18
--- /dev/null
+++ b/gcc/testsuite/g++.dg/parse/crash52.C
@@ -0,0 +1,3 @@
+// PR c++/39053
+
+void foo() = // { dg-error "initialized|expected" }