]> granicus.if.org Git - clang/commitdiff
Add some missing checks for C++1y digit separators that don't in fact separate
authorRichard Smith <richard-llvm@metafoo.co.uk>
Tue, 22 Apr 2014 23:50:25 +0000 (23:50 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Tue, 22 Apr 2014 23:50:25 +0000 (23:50 +0000)
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...
=)

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@206932 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Lex/LiteralSupport.cpp
test/Lexer/cxx1y_digit_separators.cpp

index ddfa10c69879ae188bd27fdca0c1b2ef2e6ffa39..80e025def7b3e9319deecf6b21dd90df72e291d7 100644 (file)
@@ -765,6 +765,7 @@ void NumericLiteralParser::ParseNumberStartingWithZero(SourceLocation TokLoc) {
       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::ParseNumberStartingWithZero(SourceLocation TokLoc) {
     // 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::ParseNumberStartingWithZero(SourceLocation TokLoc) {
         hadError = true;
         return;
       }
+      checkSeparator(TokLoc, s, CSK_BeforeDigits);
       s = first_non_digit;
 
       if (!PP.getLangOpts().HexFloats)
@@ -858,9 +861,11 @@ void NumericLiteralParser::ParseNumberStartingWithZero(SourceLocation TokLoc) {
     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::ParseNumberStartingWithZero(SourceLocation TokLoc) {
     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),
index dcfb6d093fe18dd574415f1edc980a83a6a0077c..c4c6aee963da0fb5b6a6a54952c3c2e339756286 100644 (file)
@@ -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