Author: rsmith Date: Tue Feb 9 16:34:35 2016 New Revision: 260307 URL: http://llvm.org/viewvc/llvm-project?rev=260307&view=rev Log: PR26349: correctly check whether a digit sequence is empty in the presence of digit separators.
Modified: cfe/trunk/include/clang/Lex/LiteralSupport.h cfe/trunk/lib/Lex/LiteralSupport.cpp cfe/trunk/test/Lexer/cxx1y_digit_separators.cpp Modified: cfe/trunk/include/clang/Lex/LiteralSupport.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/LiteralSupport.h?rev=260307&r1=260306&r2=260307&view=diff ============================================================================== --- cfe/trunk/include/clang/Lex/LiteralSupport.h (original) +++ cfe/trunk/include/clang/Lex/LiteralSupport.h Tue Feb 9 16:34:35 2016 @@ -108,6 +108,12 @@ private: static bool isDigitSeparator(char C) { return C == '\''; } + /// \brief Determine whether the sequence of characters [Start, End) contains + /// any real digits (not digit separators). + bool containsDigits(const char *Start, const char *End) { + return Start != End && (Start + 1 != End || !isDigitSeparator(Start[0])); + } + enum CheckSeparatorKind { CSK_BeforeDigits, CSK_AfterDigits }; /// \brief Ensure that we don't have a digit separator here. Modified: cfe/trunk/lib/Lex/LiteralSupport.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/LiteralSupport.cpp?rev=260307&r1=260306&r2=260307&view=diff ============================================================================== --- cfe/trunk/lib/Lex/LiteralSupport.cpp (original) +++ cfe/trunk/lib/Lex/LiteralSupport.cpp Tue Feb 9 16:34:35 2016 @@ -700,7 +700,7 @@ void NumericLiteralParser::ParseDecimalO saw_exponent = true; if (*s == '+' || *s == '-') s++; // sign const char *first_non_digit = SkipDigits(s); - if (first_non_digit != s) { + if (containsDigits(s, first_non_digit)) { checkSeparator(TokLoc, s, CSK_BeforeDigits); s = first_non_digit; } else { @@ -771,19 +771,21 @@ void NumericLiteralParser::ParseNumberSt radix = 16; DigitsBegin = s; s = SkipHexDigits(s); - bool noSignificand = (s == DigitsBegin); + bool HasSignificandDigits = containsDigits(DigitsBegin, s); if (s == ThisTokEnd) { // Done. } else if (*s == '.') { s++; saw_period = true; const char *floatDigitsBegin = s; - checkSeparator(TokLoc, s, CSK_BeforeDigits); s = SkipHexDigits(s); - noSignificand &= (floatDigitsBegin == s); + if (containsDigits(floatDigitsBegin, s)) + HasSignificandDigits = true; + if (HasSignificandDigits) + checkSeparator(TokLoc, floatDigitsBegin, CSK_BeforeDigits); } - if (noSignificand) { + if (!HasSignificandDigits) { PP.Diag(PP.AdvanceToTokenCharacter(TokLoc, s - ThisTokBegin), diag::err_hexconstant_requires) << 1; hadError = true; @@ -799,7 +801,7 @@ void NumericLiteralParser::ParseNumberSt saw_exponent = true; if (*s == '+' || *s == '-') s++; // sign const char *first_non_digit = SkipDigits(s); - if (first_non_digit == s) { + if (!containsDigits(s, first_non_digit)) { PP.Diag(PP.AdvanceToTokenCharacter(TokLoc, Exponent-ThisTokBegin), diag::err_exponent_has_no_digits); hadError = true; 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=260307&r1=260306&r2=260307&view=diff ============================================================================== --- cfe/trunk/test/Lexer/cxx1y_digit_separators.cpp (original) +++ cfe/trunk/test/Lexer/cxx1y_digit_separators.cpp Tue Feb 9 16:34:35 2016 @@ -48,6 +48,9 @@ namespace floating { 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 = 0x.'p1f; // expected-error {{hexadecimal floating constants require a significand}} + float v = 0e'f; // expected-error {{exponent has no digits}} + float w = 0x0p'f; // expected-error {{exponent has no digits}} } #line 123'456 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits