Fix PR2220, making diagnostics for unexpected tokens in pp expressions
more nice.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@49619 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/clang/Basic/DiagnosticKinds.def b/include/clang/Basic/DiagnosticKinds.def
index 5afbfff..0c953ca 100644
--- a/include/clang/Basic/DiagnosticKinds.def
+++ b/include/clang/Basic/DiagnosticKinds.def
@@ -207,8 +207,10 @@
"division by zero in preprocessor expression")
DIAG(err_pp_remainder_by_zero, ERROR,
"remainder by zero in preprocessor expression")
-DIAG(err_pp_expr_bad_token, ERROR,
- "token is not valid in preprocessor expressions")
+DIAG(err_pp_expr_bad_token_binop, ERROR,
+ "token is not a valid binary operator in a preprocessor subexpression")
+DIAG(err_pp_expr_bad_token_start_expr, ERROR,
+ "invalid token at start of a preprocessor expression")
DIAG(err_pp_invalid_poison, ERROR,
"can only poison identifier tokens")
DIAG(err_pp_used_poisoned_id, ERROR,
diff --git a/lib/Lex/PPExpressions.cpp b/lib/Lex/PPExpressions.cpp
index cca7628..398567b 100644
--- a/lib/Lex/PPExpressions.cpp
+++ b/lib/Lex/PPExpressions.cpp
@@ -131,7 +131,7 @@
switch (PeekTok.getKind()) {
default: // Non-value token.
- PP.Diag(PeekTok, diag::err_pp_expr_bad_token);
+ PP.Diag(PeekTok, diag::err_pp_expr_bad_token_start_expr);
return true;
case tok::eom:
case tok::r_paren:
@@ -349,7 +349,7 @@
unsigned PeekPrec = getPrecedence(PeekTok.getKind());
// If this token isn't valid, report the error.
if (PeekPrec == ~0U) {
- PP.Diag(PeekTok, diag::err_pp_expr_bad_token);
+ PP.Diag(PeekTok, diag::err_pp_expr_bad_token_binop);
return true;
}
@@ -392,7 +392,7 @@
// If this token isn't valid, report the error.
if (PeekPrec == ~0U) {
- PP.Diag(PeekTok, diag::err_pp_expr_bad_token);
+ PP.Diag(PeekTok, diag::err_pp_expr_bad_token_binop);
return true;
}
diff --git a/test/Preprocessor/expr_invalid_tok.c b/test/Preprocessor/expr_invalid_tok.c
new file mode 100644
index 0000000..2918bc6
--- /dev/null
+++ b/test/Preprocessor/expr_invalid_tok.c
@@ -0,0 +1,10 @@
+// RUN: not clang -E %s 2>&1 | grep 'invalid token at start of a preprocessor expression'
+// RUN: not clang -E %s 2>&1 | grep 'token is not a valid binary operator in a preprocessor subexpression'
+// PR2220
+
+#if 1 * * 2
+#endif
+
+#if 4 [ 2
+#endif
+