[cfe-commits] r54035 - in /cfe/trunk: include/clang/Basic/DiagnosticKinds.def lib/Lex/LiteralSupport.cpp

Chris Lattner sabre at nondot.org
Fri Jul 25 11:18:34 PDT 2008


Author: lattner
Date: Fri Jul 25 13:18:34 2008
New Revision: 54035

URL: http://llvm.org/viewvc/llvm-project?rev=54035&view=rev
Log:
In c89 mode accept hex fp constants as an extension:

t2.c:1:17: warning: hexadecimal floating constants are a C99 feature
long double d = 0x0.0000003ffffffff00000p-16357L;
                ^

instead of emitting a weird error message that doesn't make sense:

t2.c:1:41: error: hexadecimal floating constants require an exponent
long double d = 0x0.0000003ffffffff00000p-16357L;
                                        ^

rdar://6096838

Modified:
    cfe/trunk/include/clang/Basic/DiagnosticKinds.def
    cfe/trunk/lib/Lex/LiteralSupport.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticKinds.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticKinds.def?rev=54035&r1=54034&r2=54035&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticKinds.def (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticKinds.def Fri Jul 25 13:18:34 2008
@@ -877,6 +877,8 @@
      "invalid digit '%0' in decimal constant")
 DIAG(err_hexconstant_requires_exponent, ERROR,
      "hexadecimal floating constants require an exponent")
+DIAG(ext_hexconstant_invalid, EXTENSION,
+     "hexadecimal floating constants are a C99 feature")
 DIAG(err_typecheck_subscript_value, ERROR,
      "subscripted value is neither array nor pointer")
 DIAG(err_typecheck_subscript, ERROR,

Modified: cfe/trunk/lib/Lex/LiteralSupport.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/LiteralSupport.cpp?rev=54035&r1=54034&r2=54035&view=diff

==============================================================================
--- cfe/trunk/lib/Lex/LiteralSupport.cpp (original)
+++ cfe/trunk/lib/Lex/LiteralSupport.cpp Fri Jul 25 13:18:34 2008
@@ -354,18 +354,21 @@
     }
     // A binary exponent can appear with or with a '.'. If dotted, the
     // binary exponent is required. 
-    if ((*s == 'p' || *s == 'P') && PP.getLangOptions().HexFloats) {
+    if (*s == 'p' || *s == 'P') {
       const char *Exponent = s;
       s++;
       saw_exponent = true;
       if (*s == '+' || *s == '-')  s++; // sign
       const char *first_non_digit = SkipDigits(s);
-      if (first_non_digit != s) {
-        s = first_non_digit;
-      } else {
+      if (first_non_digit == s) {
         Diag(PP.AdvanceToTokenCharacter(TokLoc, Exponent-ThisTokBegin),
              diag::err_exponent_has_no_digits);
+        return;
       }
+      s = first_non_digit;
+      
+      if (!PP.getLangOptions().HexFloats)
+        Diag(TokLoc, diag::ext_hexconstant_invalid);
     } else if (saw_period) {
       Diag(PP.AdvanceToTokenCharacter(TokLoc, s-ThisTokBegin),
            diag::err_hexconstant_requires_exponent);





More information about the cfe-commits mailing list