Skip to content

Commit 7c6c016

Browse files
committed
Implement isDeleted in new paradigm
1 parent a57c59b commit 7c6c016

File tree

5 files changed

+22
-17
lines changed

5 files changed

+22
-17
lines changed

src/clang.rs

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -745,25 +745,12 @@ impl Cursor {
745745
}
746746
}
747747

748-
/// Is the referent a defaulted function?
749-
pub fn is_defaulted_function(&self) -> bool {
750-
unsafe { clang_CXXMethod_isDefaulted(self.x) != 0 }
751-
}
752-
753748
/// Is the referent a deleted function?
754749
pub fn is_deleted_function(&self) -> bool {
755-
// Unfortunately, libclang doesn't yet have an API for checking if a
756-
// member function is deleted, but the following should be a good
757-
// enough approximation.
758-
// Deleted functions are implicitly inline according to paragraph 4 of
759-
// [dcl.fct.def.delete] in the C++ standard. Normal inline functions
760-
// have a definition in the same translation unit, so if this is an
761-
// inline function without a definition, and it's not a defaulted
762-
// function, we can reasonably safely conclude that it's a deleted
763-
// function.
764-
self.is_inlined_function() &&
765-
self.definition().is_none() &&
766-
!self.is_defaulted_function()
750+
match self.node {
751+
ASTNode::Decl(d) => unsafe { clang_interface::Decl_isDeleted(d) },
752+
_ => false,
753+
}
767754
}
768755

769756
/// Get the width of this cursor's referent bit field, or `None` if the

src/clang/clang_interface.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ bool CursorKind_isInvalid(CXCursorKind kind);
108108

109109
const Decl *Decl_getLexicalParent(const Decl *D);
110110
const Decl *Decl_getSemanticParent(const Decl *D);
111+
bool Decl_isDeleted(const Decl *D);
111112
const Decl *Decl_getDefinition(const Decl *D, bool isReference);
112113
const Decl *Decl_getReferenced(const Decl *D);
113114
const Decl *Decl_getCanonical(const Decl *D);

src/clang/clang_interface.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7837,6 +7837,9 @@ extern "C" {
78377837
extern "C" {
78387838
pub fn Decl_getSemanticParent(D: *const clang_Decl) -> *const clang_Decl;
78397839
}
7840+
extern "C" {
7841+
pub fn Decl_isDeleted(D: *const clang_Decl) -> bool;
7842+
}
78407843
extern "C" {
78417844
pub fn Decl_getDefinition(
78427845
D: *const clang_Decl,

src/clang/libclang_compat.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,6 +1108,12 @@ CXDiagnosticSeverity Diagnostic_getSeverity(const StoredDiagnostic *D) {
11081108
llvm_unreachable("Invalid diagnostic level");
11091109
}
11101110

1111+
// Adapted from getCursorAvailabilityForDecl in CIndex.cpp
1112+
bool Decl_isDeleted(const Decl *D)
1113+
{
1114+
return isa<FunctionDecl>(D) && cast<FunctionDecl>(D)->isDeleted();
1115+
}
1116+
11111117
// Adapted from clang_getCursorDefinition in CIndex.cpp
11121118
const Decl *Decl_getDefinition(const Decl *D, bool isReference) {
11131119
if (!D)

tests/expectations/tests/deleted-function.rs

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)