]> granicus.if.org Git - clang/commitdiff
In Microsoft compatibility mode, don't parse the exponent as part of
authorDouglas Gregor <dgregor@apple.com>
Mon, 30 Aug 2010 14:50:47 +0000 (14:50 +0000)
committerDouglas Gregor <dgregor@apple.com>
Mon, 30 Aug 2010 14:50:47 +0000 (14:50 +0000)
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

lib/Lex/Lexer.cpp
test/Lexer/ms-extensions.c

index b4cafb49f8c1140a7fd444dca693eaf196bd91a1..4fd35be19c20b8c0ad5ed71ddf6c4660d31ec213 100644 (file)
@@ -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.
index 97e660080d45f81041819bbc50f633dde080563d..5b45ab4ab54fb12632d2b68813651c0e736964e6 100644 (file)
@@ -23,3 +23,11 @@ void a() {
         unsigned short s = USHORT;
         unsigned char c = UCHAR;
 }
+
+void pr_7968()
+{
+  int var1 = 0x1111111e+1;
+  int var2 = 0X1111111e+1;
+  int var3 = 0xe+1;
+  int var4 = 0XE+1;
+}