[PATCH] D47687: [Sema] Missing -Wlogical-op-parentheses warnings in macros (PR18971)

Volodymyr Sapsai via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Jul 6 13:17:03 PDT 2018

vsapsai added a comment.

In https://reviews.llvm.org/D47687#1136351, @Higuoxing wrote:

> Sorry, It seems a little bit difficult for me to add a proper fix-it hint for expressions in macros, because I cannot find the exact position of the last char of the token on right hand side of operator. Any suggestion?

Can you please clarify what exactly isn't working? `SuggestParentheses` is doing most of what you need but in this case it doesn't work because of macro locations:

  static void SuggestParentheses(Sema &Self, SourceLocation Loc,
                                 const PartialDiagnostic &Note,
                                 SourceRange ParenRange) {
    SourceLocation EndLoc = Self.getLocForEndOfToken(ParenRange.getEnd());
    if (ParenRange.getBegin().isFileID() && ParenRange.getEnd().isFileID() &&
        EndLoc.isValid()) {
      Self.Diag(Loc, Note)
        << FixItHint::CreateInsertion(ParenRange.getBegin(), "(")
        << FixItHint::CreateInsertion(EndLoc, ")");
    } else {
      // We can't display the parentheses, so just show the bare note.
      Self.Diag(Loc, Note) << ParenRange;

Hope this gives you an idea how you can try to make fix-its work.


More information about the cfe-commits mailing list