diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 35ea64b52b32830229801ade7c42cd5d62a515a2..b649072989ac82f7881c3fda752a7feaf0ac60b8 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2010-01-01  Joseph Myers  <joseph@codesourcery.com>
+
+	PR preprocessor/41947
+	* gcc.dg/c99-hexfloat-3.c: New test.
+
 2010-01-01  Richard Guenther  <rguenther@suse.de>
 
 	PR c/42570
diff --git a/gcc/testsuite/gcc.dg/c99-hexfloat-3.c b/gcc/testsuite/gcc.dg/c99-hexfloat-3.c
new file mode 100644
index 0000000000000000000000000000000000000000..62dc4956ab95e6b8910cfa65c32d5050ad68165d
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/c99-hexfloat-3.c
@@ -0,0 +1,25 @@
+/* Test syntax of hexadecimal floating point constants: at least one
+   digit needed before or after point.  PR 41947.  */
+/* { dg-do compile } */
+/* { dg-options "-std=iso9899:1999 -pedantic-errors" } */
+
+double d0 = 0x0.0p0;
+double d1 = 0x.0p0;
+double d2 = 0x0.p0;
+double d3 = 0x0.0p+0;
+double d4 = 0x.0p+0;
+double d5 = 0x0.p+0;
+double d6 = 0x0.0p-0;
+double d7 = 0x.0p-0;
+double d8 = 0x0.p-0;
+
+double e0 = 0x.p0; /* { dg-error "no digits" } */
+double e1 = 0x0.; /* { dg-error "require an exponent" } */
+double e2 = 0x.0; /* { dg-error "require an exponent" } */
+double e3 = 0x0.0; /* { dg-error "require an exponent" } */
+double e4 = 0x0.0p; /* { dg-error "exponent has no digits" } */
+double e5 = 0x0.0pf; /* { dg-error "exponent has no digits" } */
+double e6 = 0x0.0p+; /* { dg-error "exponent has no digits" } */
+double e7 = 0x0.0p+f; /* { dg-error "exponent has no digits" } */
+double e8 = 0x0.0p-; /* { dg-error "exponent has no digits" } */
+double e9 = 0x0.0p-f; /* { dg-error "exponent has no digits" } */
diff --git a/libcpp/ChangeLog b/libcpp/ChangeLog
index af05ca315151a7cb8b4c2b143b706a1e36428f58..d35186ccff0d07b3f08a75412799bc233e8f1cee 100644
--- a/libcpp/ChangeLog
+++ b/libcpp/ChangeLog
@@ -1,3 +1,9 @@
+2010-01-01  Joseph Myers  <joseph@codesourcery.com>
+
+	PR preprocessor/41947
+	* expr.c (cpp_classify_number): Give error for hexadecimal
+	floating-point constant with no digits before or after point.
+
 2009-11-20  Arnaud Charlet  <charlet@adacore.com>
 
 	* macro.c (enter_macro_context): Call cb.used callback if defined.
diff --git a/libcpp/expr.c b/libcpp/expr.c
index 96dd2fde24ca93e538b3a40083c4fa59dc70fbce..60cb2816a7ab9d3fed07c567362e62dea5ef24c0 100644
--- a/libcpp/expr.c
+++ b/libcpp/expr.c
@@ -1,6 +1,6 @@
 /* Parse C expressions for cpplib.
    Copyright (C) 1987, 1992, 1994, 1995, 1997, 1998, 1999, 2000, 2001,
-   2002, 2004, 2008, 2009 Free Software Foundation.
+   2002, 2004, 2008, 2009, 2010 Free Software Foundation.
    Contributed by Per Bothner, 1994.
 
 This program is free software; you can redistribute it and/or modify it
@@ -229,6 +229,7 @@ cpp_classify_number (cpp_reader *pfile, const cpp_token *token)
   const uchar *limit;
   unsigned int max_digit, result, radix;
   enum {NOT_FLOAT = 0, AFTER_POINT, AFTER_EXPON} float_flag;
+  bool seen_digit;
 
   /* If the lexer has done its job, length one can only be a single
      digit.  Fast-path this very common case.  */
@@ -239,6 +240,7 @@ cpp_classify_number (cpp_reader *pfile, const cpp_token *token)
   float_flag = NOT_FLOAT;
   max_digit = 0;
   radix = 10;
+  seen_digit = false;
 
   /* First, interpret the radix.  */
   if (*str == '0')
@@ -267,6 +269,7 @@ cpp_classify_number (cpp_reader *pfile, const cpp_token *token)
 
       if (ISDIGIT (c) || (ISXDIGIT (c) && radix == 16))
 	{
+	  seen_digit = true;
 	  c = hex_value (c);
 	  if (c > max_digit)
 	    max_digit = c;
@@ -332,6 +335,9 @@ cpp_classify_number (cpp_reader *pfile, const cpp_token *token)
 	  return CPP_N_INVALID;
 	}
 
+      if (radix == 16 && !seen_digit)
+	SYNTAX_ERROR ("no digits in hexadecimal floating constant");
+
       if (radix == 16 && CPP_PEDANTIC (pfile) && !CPP_OPTION (pfile, c99))
 	cpp_error (pfile, CPP_DL_PEDWARN,
 		   "use of C99 hexadecimal floating constant");