llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.26k stars 11.67k forks source link

recordDecl(unless(isDefinition())) is not the inverse of recordDecl(isDefinition()) #26987

Open LegalizeAdulthood opened 8 years ago

LegalizeAdulthood commented 8 years ago
Bugzilla Link 26613
Version unspecified
OS Linux

Extended Description

The expectation is that recordDecl(unless(isDefinition())) should only match declarations of struct/class/union that does not contain a body. However, this doesn't work.

Example:

clanger> cat ../llvm/tools/clang/tools/extra/test/clang-tidy/readability-redundant-fwd-decl.cpp 
// RUN: %check_clang_tidy %s readability-redundant-fwd-decl %t

class Foo;
class Foo;
// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: redundant forward declaration [readability-redundant-fwd-decl]

class Bar {
public:
    int i;
};

class Bar;
~/dev/build
clanger> bin/clang-query ../llvm/tools/clang/tools/extra/test/clang-tidy/readability-redundant-fwd-decl.cpp -- -std=c++11
clang-query> match recordDecl(isDefinition())

Match #1:

/home/richard/dev/build/../llvm/tools/clang/tools/extra/test/clang-tidy/readability-redundant-fwd-decl.cpp:7:1: note: "root" binds here
class Bar {
^~~~~~~~~~~
1 match.
clang-query> match recordDecl(unless(isDefinition()))

Match #1:

/home/richard/dev/build/../llvm/tools/clang/tools/extra/test/clang-tidy/readability-redundant-fwd-decl.cpp:3:1: note: "root" binds here
class Foo;
^~~~~~~~~

Match #2:

/home/richard/dev/build/../llvm/tools/clang/tools/extra/test/clang-tidy/readability-redundant-fwd-decl.cpp:4:1: note: "root" binds here
class Foo;
^~~~~~~~~

Match #3:

/home/richard/dev/build/../llvm/tools/clang/tools/extra/test/clang-tidy/readability-redundant-fwd-decl.cpp:7:1: note: "root" binds here
class Bar {
^~~~~~~~~

Match #4:

/home/richard/dev/build/../llvm/tools/clang/tools/extra/test/clang-tidy/readability-redundant-fwd-decl.cpp:12:1: note: "root" binds here
class Bar;
^~~~~~~~~
4 matches.
clang-query>
llvmbot commented 2 years ago

@llvm/issue-subscribers-bug

LegalizeAdulthood commented 2 years ago

Still an issue in 14.0