diff options
author | Douglas Gregor <dgregor@apple.com> | 2010-08-30 14:50:47 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2010-08-30 14:50:47 +0000 |
commit | a75ec43d625753b4439b0d6f70bd988444c74617 (patch) | |
tree | d3a0d144d506b211c77854f0bc7ec7fe9cc4ad7e /lib/Lex/Lexer.cpp | |
parent | 5c0ca52e40e0b9e3c2da7abba47b18e468c84060 (diff) |
In Microsoft compatibility mode, don't parse the exponent as part of
the pp-number in a hexadecimal floating point literal, from Francois
Pichet! Fixes PR7968.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@112481 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Lex/Lexer.cpp')
-rw-r--r-- | lib/Lex/Lexer.cpp | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/lib/Lex/Lexer.cpp b/lib/Lex/Lexer.cpp index b4cafb49f8..4fd35be19c 100644 --- a/lib/Lex/Lexer.cpp +++ b/lib/Lex/Lexer.cpp @@ -925,6 +925,11 @@ FinishIdentifier: } } +/// isHexaLiteral - Return true if Start points to a hex constant. +static inline bool isHexaLiteral(const char* Start, const char* End) { + return ((End - Start > 2) && Start[0] == '0' && + (Start[1] == 'x' || Start[1] == 'X')); +} /// LexNumericConstant - Lex the remainder of a integer or floating point /// constant. From[-1] is the first character lexed. Return the end of the @@ -940,7 +945,11 @@ void Lexer::LexNumericConstant(Token &Result, const char *CurPtr) { } // If we fell out, check for a sign, due to 1e+12. If we have one, continue. - if ((C == '-' || C == '+') && (PrevCh == 'E' || PrevCh == 'e')) + // If we are in Microsoft mode, don't continue if the constant is hex. + // For example, MSVC will accept the following as 3 tokens: 0x1234567e+1 + if ((C == '-' || C == '+') && (PrevCh == 'E' || PrevCh == 'e') && + (!PP || !PP->getLangOptions().Microsoft || + !isHexaLiteral(BufferPtr, CurPtr))) return LexNumericConstant(Result, ConsumeChar(CurPtr, Size, Result)); // If we have a hex FP constant, continue. |