Unfortunately, we can't accept the UCN as an extension because we're
required to treat it as two tokens for preprocessing purposes.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173622
91177308-0d34-0410-b5e6-
96231b3b80d8
def warn_cxx98_compat_literal_ucn_control_character : Warning<
"universal character name referring to a control character "
"is incompatible with C++98">, InGroup<CXX98Compat>, DefaultIgnore;
+def warn_ucn_not_valid_in_c89 : Warning<
+ "universal character names are only valid in C99 or C++; "
+ "treating as '\\' followed by identifier">, InGroup<Unicode>;
+def warn_ucn_not_valid_in_c89_literal : ExtWarn<
+ "universal character names are only valid in C99 or C++">, InGroup<Unicode>;
// Literal
"support">, InGroup<OverlengthStrings>;
def err_character_too_large : Error<
"character too large for enclosing character literal type">;
-def warn_ucn_not_valid_in_c89 : ExtWarn<
- "unicode escape sequences are only valid in C99 or C++">, InGroup<Unicode>;
def warn_cxx98_compat_unicode_literal : Warning<
"unicode literals are incompatible with C++98">,
InGroup<CXX98Compat>, DefaultIgnore;
uint32_t Lexer::tryReadUCN(const char *&StartPtr, const char *SlashLoc,
Token *Result) {
- assert(LangOpts.CPlusPlus || LangOpts.C99);
-
unsigned CharSize;
char Kind = getCharAndSize(StartPtr, CharSize);
else
return 0;
+ if (!LangOpts.CPlusPlus && !LangOpts.C99) {
+ Diag(SlashLoc, diag::warn_ucn_not_valid_in_c89);
+ return 0;
+ }
+
const char *CurPtr = StartPtr + CharSize;
const char *KindLoc = &CurPtr[-1];
}
}
}
-
+
return 0;
}
if (!Features.CPlusPlus && !Features.C99 && Diags)
Diag(Diags, Features, Loc, ThisTokBegin, UcnBegin, ThisTokBuf,
- diag::warn_ucn_not_valid_in_c89);
+ diag::warn_ucn_not_valid_in_c89_literal);
return true;
}
}
void test3() {
- (void)L"\u1234"; // expected-error {{unicode escape sequences are only valid in C99 or C++}}
- (void)L'\u1234'; // expected-error {{unicode escape sequences are only valid in C99 or C++}}
+ (void)L"\u1234"; // expected-error {{universal character names are only valid in C99 or C++}}
+ (void)L'\u1234'; // expected-error {{universal character names are only valid in C99 or C++}}
}
#define PREFIX(x) foo ## x
int *p = &PREFIX(0p+1);
return p[-1];
}
+
+#define MY_UCN \u00FC // expected-warning {{universal character names are only valid in C99 or C++; treating as '\' followed by identifier}}