[cfe-commits] r150072 - in /cfe/trunk: lib/Lex/LiteralSupport.cpp test/Lexer/hexfloat.cpp
Aaron Ballman
aaron at aaronballman.com
Wed Feb 8 05:36:34 PST 2012
Author: aaronballman
Date: Wed Feb 8 07:36:33 2012
New Revision: 150072
URL: http://llvm.org/viewvc/llvm-project?rev=150072&view=rev
Log:
Fixing hex floating literal support so that it handles 0x.2p2 properly.
Modified:
cfe/trunk/lib/Lex/LiteralSupport.cpp
cfe/trunk/test/Lexer/hexfloat.cpp
Modified: cfe/trunk/lib/Lex/LiteralSupport.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/LiteralSupport.cpp?rev=150072&r1=150071&r2=150072&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/LiteralSupport.cpp (original)
+++ cfe/trunk/lib/Lex/LiteralSupport.cpp Wed Feb 8 07:36:33 2012
@@ -546,22 +546,27 @@
// Handle a hex number like 0x1234.
if ((*s == 'x' || *s == 'X') && (isxdigit(s[1]) || s[1] == '.')) {
s++;
- if (!isxdigit(*s)) {
- PP.Diag(PP.AdvanceToTokenCharacter(TokLoc, s-ThisTokBegin), \
- diag::err_hexconstant_requires_digits);
- hadError = true;
- return;
- }
radix = 16;
DigitsBegin = s;
s = SkipHexDigits(s);
+ bool noSignificand = (s == DigitsBegin);
if (s == ThisTokEnd) {
// Done.
} else if (*s == '.') {
s++;
saw_period = true;
+ const char *floatDigitsBegin = s;
s = SkipHexDigits(s);
+ noSignificand &= (floatDigitsBegin == s);
+ }
+
+ if (noSignificand) {
+ PP.Diag(PP.AdvanceToTokenCharacter(TokLoc, s-ThisTokBegin), \
+ diag::err_hexconstant_requires_digits);
+ hadError = true;
+ return;
}
+
// A binary exponent can appear with or with a '.'. If dotted, the
// binary exponent is required.
if (*s == 'p' || *s == 'P') {
Modified: cfe/trunk/test/Lexer/hexfloat.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Lexer/hexfloat.cpp?rev=150072&r1=150071&r2=150072&view=diff
==============================================================================
--- cfe/trunk/test/Lexer/hexfloat.cpp (original)
+++ cfe/trunk/test/Lexer/hexfloat.cpp Wed Feb 8 07:36:33 2012
@@ -2,4 +2,6 @@
// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify -pedantic %s
float f = 0x1p+1; // expected-warning{{hexadecimal floating constants are a C99 feature}}
double e = 0x.p0; //expected-error{{hexadecimal floating constants require a significand}}
-
+double d = 0x.2p2; // expected-warning{{hexadecimal floating constants are a C99 feature}}
+float g = 0x1.2p2; // expected-warning{{hexadecimal floating constants are a C99 feature}}
+double h = 0x1.p2; // expected-warning{{hexadecimal floating constants are a C99 feature}}
More information about the cfe-commits
mailing list