Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

llvm-prefer-isa-or-dyn-cast-in-conditions quick fix introduces error #43518

Open Quuxplusone opened 4 years ago

Quuxplusone commented 4 years ago
Bugzilla Link PR44548
Status NEW
Importance P enhancement
Reported by Nathan Ridge (zeratul976@hotmail.com)
Reported on 2020-01-14 11:09:45 -0800
Last modified on 2020-01-15 15:33:24 -0800
Version unspecified
Hardware PC Linux
CC alexfh@google.com, djasper@google.com, eugene.zelenko@gmail.com, hintonda@gmail.com, klimek@google.com
Fixed by commit(s)
Attachments
Blocks
Blocked by
See also
Given code like the following:

#include "llvm/Support/Casting.h"
#include "clang/AST/Decl.h"

namespace clang {
  using llvm::isa;

  void foo(Decl *D) {
    if (D && isa<TranslationUnitDecl>(D)) {      // <---
    }
  }
}

clang-tidy's "llvm-prefer-isa-or-dyn-cast-in-conditions' checker issues this
diagnostic on the indicated line:

"Isa_and_nonnull<> is preferred over an explicit test for null followed by
calling isa<> (fix available)"

along with a quick fix that changes the line to:

  if (isa_and_nonnull<TranslationUnitDecl>(D)) {

However, the quick fix does not qualify isa_and_nonull, nor does it introduce a
using-declaration for it, resulting in invalid code.
Quuxplusone commented 4 years ago

Hi Nathan,

Thanks for reporting this.

I'll take a look and see if I can come up with a fix. I hesitate to always prepend 'llvm::', but should cover this use case.

Quuxplusone commented 4 years ago

Probably best solution would be to not produce fix-it.

using declaration may be unused and should be removed, but this is not task for this check.