[Lexer] Allow UCN for dollar symbol '\u0024' in identifiers when using -fdollars...
authorScott Egerton <scott.egerton@embecosm.com>
Wed, 15 Jan 2020 11:28:55 +0000 (11:28 +0000)
committerScott Egerton <scott.egerton@embecosm.com>
Wed, 15 Jan 2020 11:28:57 +0000 (11:28 +0000)
Summary:
Previously, the -fdollars-in-identifiers flag allows the '$' symbol to be used
in an identifier but the universal character name equivalent '\u0024' is not
allowed.
This patch changes this, so that \u0024 is valid in identifiers.

Reviewers: rsmith, jordan_rose

Reviewed By: rsmith

Subscribers: dexonsmith, simoncook, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D71758

clang/lib/Lex/Lexer.cpp
clang/test/Preprocessor/ucn-pp-identifier.c

index 902b173..648bda2 100644 (file)
@@ -1431,6 +1431,8 @@ void Lexer::SetByteOffset(unsigned Offset, bool StartOfLine) {
 static bool isAllowedIDChar(uint32_t C, const LangOptions &LangOpts) {
   if (LangOpts.AsmPreprocessor) {
     return false;
+  } else if (LangOpts.DollarIdents && '$' == C) {
+    return true;
   } else if (LangOpts.CPlusPlus11 || LangOpts.C11) {
     static const llvm::sys::UnicodeCharSet C11AllowedIDChars(
         C11AllowedIDCharRanges);
index f045e38..0929412 100644 (file)
@@ -28,8 +28,7 @@
 #define \U10000000  // expected-error {{macro name must be an identifier}}
 #define \u0061  // expected-error {{character 'a' cannot be specified by a universal character name}} expected-error {{macro name must be an identifier}}
 
-// FIXME: Not clear what our behavior should be here; \u0024 is "$".
-#define a\u0024  // expected-warning {{whitespace}}
+#define a\u0024
 
 #if \u0110 // expected-warning {{is not defined, evaluates to 0}}
 #endif