[PATCH] D16673: Don't split NumericConstant tokens if a digit separator proceeds a period.

Craig Topper via cfe-commits cfe-commits at lists.llvm.org
Wed Jan 27 22:15:54 PST 2016


craig.topper created this revision.
craig.topper added a reviewer: rsmith.
craig.topper added a subscriber: cfe-commits.

Currently we split a token if a digit separator proceeds a period. This causes the digit separator to be interpreted instead as the start of a character constant token. gcc seems to keep it as a whole token for this case and issues an error for a digit separator being adjacent to a period.

Parts of NumericLiteralParser already expected that the digit separator could appear before a period and attempted to diagnose accordingly.

http://reviews.llvm.org/D16673

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

Index: test/Lexer/cxx1y_digit_separators.cpp
===================================================================
--- test/Lexer/cxx1y_digit_separators.cpp
+++ test/Lexer/cxx1y_digit_separators.cpp
@@ -38,7 +38,7 @@
   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 k = 0x0'.0p0; // expected-error {{digit separator cannot appear at end of digit sequence}}
   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}}
@@ -48,6 +48,8 @@
   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}}
+  float u = 0'.0; // expected-error {{digit separator cannot appear at end of digit sequence}}
+  float v = 1'.0; // expected-error {{digit separator cannot appear at end of digit sequence}}
 }
 
 #line 123'456
Index: lib/Lex/LiteralSupport.cpp
===================================================================
--- lib/Lex/LiteralSupport.cpp
+++ lib/Lex/LiteralSupport.cpp
@@ -775,6 +775,7 @@
     if (s == ThisTokEnd) {
       // Done.
     } else if (*s == '.') {
+      checkSeparator(TokLoc, s, CSK_AfterDigits);
       s++;
       saw_period = true;
       const char *floatDigitsBegin = s;
Index: lib/Lex/Lexer.cpp
===================================================================
--- lib/Lex/Lexer.cpp
+++ lib/Lex/Lexer.cpp
@@ -1623,7 +1623,7 @@
   if (C == '\'' && getLangOpts().CPlusPlus14) {
     unsigned NextSize;
     char Next = getCharAndSizeNoWarn(CurPtr + Size, NextSize, getLangOpts());
-    if (isIdentifierBody(Next)) {
+    if (isPreprocessingNumberBody(Next)) {
       if (!isLexingRawMode())
         Diag(CurPtr, diag::warn_cxx11_compat_digit_separator);
       CurPtr = ConsumeChar(CurPtr, Size, Result);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D16673.46223.patch
Type: text/x-patch
Size: 2413 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160128/0355f9b7/attachment.bin>


More information about the cfe-commits mailing list