From 431393eb9155517fa0579ce59c2e6a24f708f005 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Tue, 22 Apr 2014 23:50:25 +0000 Subject: [PATCH] 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... =) git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@206932 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Lex/LiteralSupport.cpp | 6 ++++++ test/Lexer/cxx1y_digit_separators.cpp | 14 ++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/lib/Lex/LiteralSupport.cpp b/lib/Lex/LiteralSupport.cpp index ddfa10c698..80e025def7 100644 --- a/lib/Lex/LiteralSupport.cpp +++ b/lib/Lex/LiteralSupport.cpp @@ -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), diff --git a/test/Lexer/cxx1y_digit_separators.cpp b/test/Lexer/cxx1y_digit_separators.cpp index dcfb6d093f..c4c6aee963 100644 --- a/test/Lexer/cxx1y_digit_separators.cpp +++ b/test/Lexer/cxx1y_digit_separators.cpp @@ -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 -- 2.40.0