]> granicus.if.org Git - clang/commitdiff
Simplify logic for avoiding concatenation after numeric constants.
authorJordan Rose <jordan_rose@apple.com>
Fri, 8 Feb 2013 22:30:31 +0000 (22:30 +0000)
committerJordan Rose <jordan_rose@apple.com>
Fri, 8 Feb 2013 22:30:31 +0000 (22:30 +0000)
I threw in a couple of test cases for UD-suffixes -- already working, but
it wasn't immediately obvious to me.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@174767 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Lex/TokenConcatenation.cpp
test/Preprocessor/output_paste_avoid.cpp [moved from test/Preprocessor/output_paste_avoid.c with 73% similarity]

index 30dc8f19d9026fef2eb008ce28d382c992b20748..0a66bba91fcd8717b9dab598c45e2d87abdf5eae 100644 (file)
@@ -12,9 +12,9 @@
 //===----------------------------------------------------------------------===//
 
 #include "clang/Lex/TokenConcatenation.h"
+#include "clang/Basic/CharInfo.h"
 #include "clang/Lex/Preprocessor.h"
 #include "llvm/Support/ErrorHandling.h"
-#include <cctype>
 using namespace clang;
 
 
@@ -240,13 +240,12 @@ bool TokenConcatenation::AvoidConcat(const Token &PrevPrevTok,
     return IsIdentifierStringPrefix(PrevTok);
 
   case tok::numeric_constant:
-    return isalnum(FirstChar) || Tok.is(tok::numeric_constant) ||
-           FirstChar == '+' || FirstChar == '-' || FirstChar == '.' ||
-           (PP.getLangOpts().CPlusPlus11 && FirstChar == '_');
+    return isPreprocessingNumberBody(FirstChar) ||
+           FirstChar == '+' || FirstChar == '-';
   case tok::period:          // ..., .*, .1234
     return (FirstChar == '.' && PrevPrevTok.is(tok::period)) ||
-    isdigit(FirstChar) ||
-    (PP.getLangOpts().CPlusPlus && FirstChar == '*');
+           isDigit(FirstChar) ||
+           (PP.getLangOpts().CPlusPlus && FirstChar == '*');
   case tok::amp:             // &&
     return FirstChar == '&';
   case tok::plus:            // ++
similarity index 73%
rename from test/Preprocessor/output_paste_avoid.c
rename to test/Preprocessor/output_paste_avoid.cpp
index 6defd1272b7dbc2453fb8c2449195714e884e5c1..689d966e867a0673847bf45c219e256b4c574948 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -E %s -o - | FileCheck -strict-whitespace %s
+// RUN: %clang_cc1 -E -std=c++11 %s -o - | FileCheck -strict-whitespace %s
 
 
 #define y(a) ..a
@@ -37,3 +37,11 @@ F: >>equal
 #define TYPEDEF(guid)   typedef [uuid(guid)]
 TYPEDEF(66504301-BE0F-101A-8BBB-00AA00300CAB) long OLE_COLOR;
 // CHECK: typedef [uuid(66504301-BE0F-101A-8BBB-00AA00300CAB)] long OLE_COLOR;
+
+// Be careful with UD-suffixes.
+#define StrSuffix() "abc"_suffix
+#define IntSuffix() 123_suffix
+UD: StrSuffix()ident
+UD: IntSuffix()ident
+// CHECK: UD: "abc"_suffix ident
+// CHECK: UD: 123_suffix ident