From: Chris Lattner Date: Sun, 13 Apr 2008 20:38:43 +0000 (+0000) Subject: Fix PR2220, making diagnostics for unexpected tokens in pp expressions X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d98d975ccdce7ec442ac26f682404cb71df40ff8;p=clang 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 5afbfffeee..0c953cad0f 100644 --- a/include/clang/Basic/DiagnosticKinds.def +++ b/include/clang/Basic/DiagnosticKinds.def @@ -207,8 +207,10 @@ DIAG(err_pp_division_by_zero, ERROR, "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 cca7628917..398567be36 100644 --- a/lib/Lex/PPExpressions.cpp +++ b/lib/Lex/PPExpressions.cpp @@ -131,7 +131,7 @@ static bool EvaluateValue(llvm::APSInt &Result, Token &PeekTok, 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 @@ static bool EvaluateDirectiveSubExpr(llvm::APSInt &LHS, unsigned MinPrec, 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 @@ static bool EvaluateDirectiveSubExpr(llvm::APSInt &LHS, unsigned MinPrec, // 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 0000000000..2918bc6536 --- /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 +