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);
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);
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits