r206932 - Add some missing checks for C++1y digit separators that don't in fact separate

Richard Smith richard-llvm at metafoo.co.uk
Tue Apr 22 16:50:26 PDT 2014


Author: rsmith
Date: Tue Apr 22 18:50:25 2014
New Revision: 206932

URL: http://llvm.org/viewvc/llvm-project?rev=206932&view=rev
Log:
Add some missing checks for C++1y digit separators that don't in fact separate
digits. Turns out we have completely separate lexing codepaths for floating
point numbers depending on whether or not they start with a zero. Who knew...
=)

Modified:
    cfe/trunk/lib/Lex/LiteralSupport.cpp
    cfe/trunk/test/Lexer/cxx1y_digit_separators.cpp

Modified: cfe/trunk/lib/Lex/LiteralSupport.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/LiteralSupport.cpp?rev=206932&r1=206931&r2=206932&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/LiteralSupport.cpp (original)
+++ cfe/trunk/lib/Lex/LiteralSupport.cpp Tue Apr 22 18:50:25 2014
@@ -765,6 +765,7 @@ void NumericLiteralParser::ParseNumberSt
       s++;
       saw_period = true;
       const char *floatDigitsBegin = s;
+      checkSeparator(TokLoc, s, CSK_BeforeDigits);
       s = SkipHexDigits(s);
       noSignificand &= (floatDigitsBegin == s);
     }
@@ -779,6 +780,7 @@ void NumericLiteralParser::ParseNumberSt
     // A binary exponent can appear with or with a '.'. If dotted, the
     // binary exponent is required.
     if (*s == 'p' || *s == 'P') {
+      checkSeparator(TokLoc, s, CSK_AfterDigits);
       const char *Exponent = s;
       s++;
       saw_exponent = true;
@@ -790,6 +792,7 @@ void NumericLiteralParser::ParseNumberSt
         hadError = true;
         return;
       }
+      checkSeparator(TokLoc, s, CSK_BeforeDigits);
       s = first_non_digit;
 
       if (!PP.getLangOpts().HexFloats)
@@ -858,9 +861,11 @@ void NumericLiteralParser::ParseNumberSt
     s++;
     radix = 10;
     saw_period = true;
+    checkSeparator(TokLoc, s, CSK_BeforeDigits);
     s = SkipDigits(s); // Skip suffix.
   }
   if (*s == 'e' || *s == 'E') { // exponent
+    checkSeparator(TokLoc, s, CSK_AfterDigits);
     const char *Exponent = s;
     s++;
     radix = 10;
@@ -868,6 +873,7 @@ void NumericLiteralParser::ParseNumberSt
     if (*s == '+' || *s == '-')  s++; // sign
     const char *first_non_digit = SkipDigits(s);
     if (first_non_digit != s) {
+      checkSeparator(TokLoc, s, CSK_BeforeDigits);
       s = first_non_digit;
     } else {
       PP.Diag(PP.AdvanceToTokenCharacter(TokLoc, Exponent-ThisTokBegin),

Modified: cfe/trunk/test/Lexer/cxx1y_digit_separators.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Lexer/cxx1y_digit_separators.cpp?rev=206932&r1=206931&r2=206932&view=diff
==============================================================================
--- cfe/trunk/test/Lexer/cxx1y_digit_separators.cpp (original)
+++ cfe/trunk/test/Lexer/cxx1y_digit_separators.cpp Tue Apr 22 18:50:25 2014
@@ -34,6 +34,20 @@ namespace floating {
   float d = 1.0'e1; // expected-error {{digit separator cannot appear at end of digit sequence}}
   float e = 1e'1; // expected-error {{digit separator cannot appear at start of digit sequence}}
   float f = 1e1'ms; // expected-error {{digit separator cannot appear at end of digit sequence}}
+  float g = 0.'0; // expected-error {{digit separator cannot appear at start of digit sequence}}
+  float h = .'0; // '; // expected-error {{expected expression}}, lexed as . followed by character literal
+  float i = 0x.'0p0; // expected-error {{digit separator cannot appear at start of digit sequence}}
+  float j = 0x'0.0p0; // expected-error {{invalid suffix 'x'0.0p0'}}
+  float k = 0x0'.0p0; // '; // expected-error {{expected ';'}}
+  float l = 0x0.'0p0; // expected-error {{digit separator cannot appear at start of digit sequence}}
+  float m = 0x0.0'p0; // expected-error {{digit separator cannot appear at end of digit sequence}}
+  float n = 0x0.0p'0; // expected-error {{digit separator cannot appear at start of digit sequence}}
+  float o = 0x0.0p0'ms; // expected-error {{digit separator cannot appear at end of digit sequence}}
+  float p = 0'e1; // expected-error {{digit separator cannot appear at end of digit sequence}}
+  float q = 0'0e1;
+  float r = 0.'0e1; // expected-error {{digit separator cannot appear at start of digit sequence}}
+  float s = 0.0'e1; // expected-error {{digit separator cannot appear at end of digit sequence}}
+  float t = 0.0e'1; // expected-error {{digit separator cannot appear at start of digit sequence}}
 }
 
 #line 123'456





More information about the cfe-commits mailing list